Paste Search Dynamic
Recent pastes
getnxtag
  1. <?php
  2.  
  3. // your code goes here
  4. $isendtag = false;
  5. $tagtyp = '';
  6.  
  7. $outtxt = '';
  8.  
  9. $intxt = '<pea this=that><divo pip>';
  10.  
  11.  
  12.  
  13.  
  14. function getnxtag(&$intxt) // $intxt is call by reference
  15. /*returns next tag ($tag) in $intxt -- removes it from $intxt
  16.  also sets (globals):
  17.    $isendtag   ~ whether char 1 in $tag == '/'
  18.    $tagtyp   ~ the actual tag name
  19.  getnxtag also takes anything(non-whitesoace) before $tag and appends it onto $outtxt
  20. */
  21. {
  22.  
  23. if(($pos=strpos($intxt, '<'))===false)  return false;
  24. //echo $pos;
  25. return $pos==0 ? '0' : $pos;
  26.  $outtxt .= substr($intxt,0,$pos);     //append to $outtxt anything before start of tag
  27.  $endpos1 = strpos($intxt,'>',1)+1;    //1 more than '>' position
  28.  $tag = substr($intxt, $pos, $endpos1-$pos);  //get tag
  29. /* |  <these tags  >
  30.   0123456789012345
  31.   |---- 14 ----| */
  32.  $intxt = substr($intxt, $endpos1);
  33.  $endtag = min(strcmp($tag,' '), strcmp($tag,'>'));
  34.  if($isendtag = substr($tag,1,1)=='/')
  35.   $tagtyp = substr($tag, 2, $endtag-2);
  36.  else
  37.  $tagtyp = substr($tag, 1, $endtag-1);
  38.  return $tag;
  39. }
  40.  
  41. $tgg = getnxtag($intxt);
  42. echo strval($tgg);
  43.  
  44.  
  45. ?>
Parsed in 0.047 seconds