Page 1 of 1

multiline preg_match_all failure

Posted: Sun Jun 17, 2007 9:53 am
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?

Posted: Sun Jun 17, 2007 9:57 am
by feyd
Can you post some example input that isn't working?

Posted: Sun Jun 17, 2007 10:04 am
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.

Posted: Sun Jun 17, 2007 10:25 am
by feyd
Make a simple version with a couple variants of containers to test.

Posted: Sun Jun 17, 2007 11:17 am
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.