Help with Converting ereg to preg_match for PHP 5.3.x

Hi everyone,

I am converting all my ereg() / eregi() functions to preg_match to comply with the latest developments in PHP 5.3.0.

Most of my conversions have been okay except for this one and I am banging my head against the wall trying to get this to work.

I hope someone can help me out on this:


Does not work:
if(preg_match('#<div class="texttitle"><a href="(.+?)">' . $category_name . '</a></div>#', trim($line1)))

This works:
if(eregi('<div class="texttitle"><a href="(.*)">' . $category_name . '</a></div>', trim($line1)))

I noticed if I used the “#” deliminator, I don’t need to escape all the / slashes. In this case, I don’t need to do this <\/a> and <\/div> for my code.

I have also tried using the “/” deliminator and escaped all the slashes but it still didn’t work.

Any help would be greatly appreciated! Thanks.


if(preg_match('#<div class="texttitle"><a href="(.+?)">' . $category_name . '</a></div>#i', trim($line1)))

Stupid me! I just added the “i” modifier after the ending “#” and it now works.