Php preg_match_all issue

I am having some difficulties in trying to write php regex expression using preg_match_all.

I’m trying to match the {php} and {/php} within the following example:

some php code

some more php code block

I have managed to get as far as matching the {php} by using the following {\s*php\s*}(.*?)

and testing using this site:

as soon as I try the following {\s*php\s*}(.*?){\s*/php\s*}

I don’t get any matches the only difference that I have done to the above is add the following at the end: {\s*/php\s*}

thank you for your help.

You should use the multiline modifier. I.e. an m at the end:

preg_match_all('~{\s*php\s*}(.*?){\s*/php\s*}~m', // etc);

You may want to add an i there too to make it case insensitive (i.e. it would then match {PHP} too)

Sorry for the delay in getting back to you. Thank you for your response I will test and let you know @rpkamp

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.