fork download
  1. <?php
  2.  
  3. $string = ' <a onmouseover=\' <a href="notreal.com">This is text inside an attribute</a> \' href=url.com>This is some inner text</a>This is outer text.
  4.  
  5. <a onmouseover=\' a=1; href="www.NotYourURL.com" ; if (3 <a && href="www.NotYourURL.com" && id="revSAR" && 6 > 3) { funRotate(href) ; } ; \' href=\'http://I...content-available-to-author-only...L.com\' id=\'revSAR\'>
  6. I am the inner text too.
  7. </a>
  8. ';
  9.  
  10. echo "split retains all spaces\n";
  11. $array = preg_split ('/(<\/?\w+(?=\s|>)(?:[^>=|&)]*|=\'[^\']*\'|="[^"]*"|=[^\'"][^\s>]*)*>|\s)/', $string, 0, PREG_SPLIT_DELIM_CAPTURE);
  12. echo implode(",",$array);
  13.  
  14. echo "\n\nsplit ignores spaces\n";
  15. $array = preg_split ('/(<\/?\w+(?=\s|>)(?:[^>=|&)]*|=\'[^\']*\'|="[^"]*"|=[^\'"][^\s>]*)*>)|\s/', $string, 0, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
  16. echo implode(",",$array);
  17.  
  18. echo "\n\nsplit ignores tags and spaces\n";
  19. $array = preg_split ('/<\/?\w+(?=\s|>)(?:[^>=|&)]*|=\'[^\']*\'|="[^"]*"|=[^\'"][^\s>]*)*>|\s/', $string, 0, PREG_SPLIT_NO_EMPTY);
  20. echo implode(",",$array);
  21.  
  22. echo "\n\nsplit ignores tags and retains spaces\n";
  23. $array = preg_split ('/<\/?\w+(?=\s|>)(?:[^>=|&)]*|=\'[^\']*\'|="[^"]*"|=[^\'"][^\s>]*)*>|(\s)/', $string, 0, PREG_SPLIT_DELIM_CAPTURE);
  24. echo implode(",",$array);
  25.  
  26.  
  27.  
Success #stdin #stdout 0.01s 20568KB
stdin
Standard input is empty
stdout
split retains all spaces
,	,,<a onmouseover=' <a href="notreal.com">This is text inside an attribute</a> ' href=url.com>,This, ,is, ,some, ,inner, ,text,</a>,This, ,is, ,outer, ,text.,
,,
,,	,,<a onmouseover=' a=1; href="www.NotYourURL.com" ; if (3 <a && href="www.NotYourURL.com" && id="revSAR" && 6 > 3) { funRotate(href) ; } ; '  href='http://I...content-available-to-author-only...L.com' id='revSAR'>,,
,,	,,	,I, ,am, ,the, ,inner, ,text, ,too.,
,,	,,	,,</a>,,
,

split ignores spaces
<a onmouseover=' <a href="notreal.com">This is text inside an attribute</a> ' href=url.com>,This,is,some,inner,text,</a>,This,is,outer,text.,<a onmouseover=' a=1; href="www.NotYourURL.com" ; if (3 <a && href="www.NotYourURL.com" && id="revSAR" && 6 > 3) { funRotate(href) ; } ; '  href='http://I...content-available-to-author-only...L.com' id='revSAR'>,I,am,the,inner,text,too.,</a>

split ignores tags and spaces
This,is,some,inner,text,This,is,outer,text.,I,am,the,inner,text,too.

split ignores tags and retains spaces
,	,,This, ,is, ,some, ,inner, ,text,This, ,is, ,outer, ,text.,
,,
,,	,,,
,,	,,	,I, ,am, ,the, ,inner, ,text, ,too.,
,,	,,	,,,
,