<?php $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. <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> '; echo "split retains all spaces\n"; $array = preg_split ('/(<\/?\w+(?=\s|>)(?:[^>=|&)]*|=\'[^\']*\'|="[^"]*"|=[^\'"][^\s>]*)*>|\s)/', $string, 0, PREG_SPLIT_DELIM_CAPTURE); echo "\n\nsplit ignores spaces\n"; $array = preg_split ('/(<\/?\w+(?=\s|>)(?:[^>=|&)]*|=\'[^\']*\'|="[^"]*"|=[^\'"][^\s>]*)*>)|\s/', $string, 0, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); echo "\n\nsplit ignores tags and spaces\n"; $array = preg_split ('/<\/?\w+(?=\s|>)(?:[^>=|&)]*|=\'[^\']*\'|="[^"]*"|=[^\'"][^\s>]*)*>|\s/', $string, 0, PREG_SPLIT_NO_EMPTY); echo "\n\nsplit ignores tags and retains spaces\n"; $array = preg_split ('/<\/?\w+(?=\s|>)(?:[^>=|&)]*|=\'[^\']*\'|="[^"]*"|=[^\'"][^\s>]*)*>|(\s)/', $string, 0, PREG_SPLIT_DELIM_CAPTURE);
Standard input is empty
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., ,, ,, ,,, ,