Page 1 of 1

Problems with preg_split function

Posted: Wed Mar 08, 2006 5:42 pm
by madox
Hi to all users on this forum. I recently found this code on www.php.net:

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);
?>
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:

Code: Select all

Array ( [0] => [1] => [2] =>
[3] => The classname is not seen as a different tag [4] =>
[5] => [6] => )
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

Posted: Wed Mar 08, 2006 7:06 pm
by madox
I'm sorry, I should post this in Regex forum, can moderators move this topic there? I'm apologize for disturbance.
Thank you in advance.

Posted: Wed Mar 08, 2006 7:08 pm
by feyd
The code is there, but since you appear to be viewing this in a browser you can't see the tags. Look in the page source, you'll see them.

Posted: Wed Mar 08, 2006 7:20 pm
by madox
@feyd
I can't believe that I was so stupid to forget to view source code of page from browser. Thank you very much for remind me on this.