multiline preg_match_all failure

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

Moderator: General Moderators

Post Reply
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

multiline preg_match_all failure

Post by superdezign »

I'm playing around with a little HTML parser I'm making. However, I'm running into a problem with preg_match_all.

If I run this pattern:

Code: Select all

preg_match_all('#(<([^/>\s]+).*?>)(.*?)(</\2>)#si', $str, $matches);
I get no matches. However, if I run this pattern (same one without the 's' modifier):

Code: Select all

preg_match_all('#(<([^/>\s]+).*?>)(.*?)(</\2>)#i', $str, $matches);
I get all single-line HTML tag matches. does anyone have any idea why it isn't working?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Can you post some example input that isn't working?
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

The input that wasn't working was an entire page's worth of HTML, so I made an extremely shortened string of HTML and it worked fine. So, the problem is somewhere in the input (which isn't good :().

The input has php code samples in it and, in order to use it, I had to escape '$' characters. Maybe there's more than needs to be escaped.

The string is defined using the <<< operator.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Make a simple version with a couple variants of containers to test.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

I will. Later on, after it's done, I'll test it with a few files and see if any escaping is necessary for outside data.

Hopefully, it's not.
Post Reply