Problems with preg_split function

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
madox
Forum Newbie
Posts: 4
Joined: Wed Mar 08, 2006 5:28 pm

Problems with preg_split function

Post 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
madox
Forum Newbie
Posts: 4
Joined: Wed Mar 08, 2006 5:28 pm

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
madox
Forum Newbie
Posts: 4
Joined: Wed Mar 08, 2006 5:28 pm

Post 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.
Post Reply