Problems with preg_split function
Posted: Wed Mar 08, 2006 5:42 pm
Hi to all users on this forum. I recently found this code on www.php.net:
Like you can see here, purpose of this code is to split string on array where each array-item is html tag or either text, but when I run it, output look like this:
I don't understand regular expressons, but I think that problem is right there. Do anyone knows how to make this code to work?
Thank you in advance.
Rgrds, maddox
Code: Select all
<?php
$html_array = array();
$pattern = '/(<(?:[^<>]+(?:"[^"]*"|\'[^\']*\')?)+>)/';
$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 ($pattern, trim ($html_string), -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
print_r($html_array);
?>Code: Select all
Array ( [0] => [1] => [2] =>
[3] => The classname is not seen as a different tag [4] =>
[5] => [6] => )Thank you in advance.
Rgrds, maddox