note 55485 added to function.preg-split

From: Date: Thu, 04 Aug 2005 19:36:32 +0000
Subject: note 55485 added to function.preg-split
Groups: php.notes 
Request: Send a blank email to php-notes+get-93089@lists.php.net to get a copy of this message
The following pattern will match a html tag: <?php $pattern = '/(<(?:[^<>]+(?:"[^"]*"|\\'[^\\']*\\')?)+>)/'; ?> So the following will nicely convert a string of html to an array, where each array-item is 1 tag or text within a tag: <?php $html_string = '<html><body><p class="a<weird>name">The classname is not seen as a different tag</p></body></html>'; $html_array = preg_split ('/(<(?:[^<>]+(?:"[^"]*"|\\'[^\\']*\\')?)+>)/', trim ($html), -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); ?> Array ( [0] => <html> [1] => <body> [2] => <p class="a<weird>name"> [3] => The classname is not seen as a different tag [4] => </p> [5] => </body> [6] => </html> ) ---- Manual Page -- http://www.php.net/manual/en/function.preg-split.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+55485 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+55485&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+55485&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+55485&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+55485&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+55485&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+55485&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+55485&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#93089) next »