ergei to preg_match

How would i change this to a preg_match as eregi is out dated now thanks for any help

[php]eregi("$begin(.*)$finish", $stuff, $content); [/php]

[php]preg_match(’#’.preg_quote($begin).’(.*)’.preg_quote($finish).’#’,$stuff,$content);[/php]

Or the lazier uncleaned way following the example:
[php]preg_match("#$begin(.*)$finish#", $stuff, $content);[/php]

[ol][li]The # could be anything (/ is popular) as long as it isn’t used in betwen, as it’s a delimeter (marks start and end of the regular expression) - hence the preg_quote in the first example[/li]
[li]Please follow the use of concatenation and preg_quote in the first code block![/li][/ol]

Thank you very much its the best answer i have had so far will give them ago

Gave them ago but come up with a blank $var I do not understand why I have tried many times to get this to work.

Does it need the /i at the end for egrei expression ?

The letter i after the final delimeter (commonly / but # in my examples) will make the regular expression case insensitive

Its strange it works with eregi but not with preg_match its the only line of code I am changing but nothing is found on the search
I can var_dump or echo and results are empty
print_r gives me a string(156)"

If it says string(156) and you can’t see anything, it’s probably returning HTML. View Source, or do:

[php]var_dump(htmlentities($thestring));[/php]

thx for your help
I figured out another way of getting the same result without the eregi or the preg_match, as the pregmatch just did not want to work I do not know why.

So not really solved but its not worth trying to fix something if it can be done a different way.

Thanks for your help.

I have firgured it out now it needed the s modifier to get it right in the end.

Can more then one modifier be used at a time ?

You can indeed, example:

/[a-z]{3,4}/gi

Matches 3 or 4 letters (a-z), globally and case insensitive

Sponsor our Newsletter | Privacy Policy | Terms of Service