pastebin

Paste Search Dynamic
Tgs
  1. <?php
  2.  
  3. // your code goes here
  4. $tgs = 'John Glenn, pale blue dot, whole earth, space (communication with ETs), Hawking (caveat of communication with ETs), Brexit (and Trump), Trump (and Brexit), Rex Tillerson, tilde symbol';
  5. $tgo = 'whole earth, John Glenn, pale blue dot, Trump (and Brexit), Rex Tillerson, space (communication with ETs), Hawking (caveat of communication with ETs), tilde symbol';
  6. $tgs_to_add="";
  7. $patt1 = '/(\A[^),]*)(,|\z)/';       //ie anchor start of tgs, no paren or comma, then comma or eos
  8. $patt2 = '/(\A.*?\)[\s]*)(,|\z)/';  //ie tgs-start-anchor, then any chars up to )  then any whsp  then comma or eos
  9. //Get next tag --> $resllt:
  10. while($tgs!=="") {       
  11.  $res1=preg_match($patt1, $tgs, $rslt1);                //remember, $rslt1[1] = the resulting part of $tgs matched (if matched, else $rslt1[1] not defined)
  12.  $res2=preg_match($patt2, $tgs, $rslt2);
  13.   /* The result coming out of above (as long as $tgs!=="") is one or the other(but not both) of $res1, $res2 == 0 (meaning no match there)
  14.          in which case the other of $rslt1[1],$rslt2[1] is the one;
  15.          or both $res1, $res2 == 1, and hav to compare strlen of $rslt1[1],$rslt2[1]                                                                                    */
  16.  if($res1==0) $resllt = $rslt2[1];
  17.  else if($res2==0)  $resllt = $rslt1[1];
  18.  else if(strlen($rslt1[1])<strlen($rslt2[1]))  $resllt = $rslt1[1];
  19.  else $resllt = $rslt2[1];
  20.  echo '|'.$resllt.'|     '/*.strlen($resllt)*/;   $tgs = trim(substr($tgs, strlen($resllt)+1));
  21. }
  22.  ?>
Parsed in 0.018 seconds