Search code examples
phpregexpcreposix-ere

ereg_replace to preg_replace?


How can I convert

ereg_replace(".*\.(.*)$","\\1",$imgfile);

to

preg_replace... ?

?

I'm having trouble with it?


Solution

  • preg_replace("/.*\.(.*)$/", "\\1", "foo.jpg")
    

    I don't know why PHP requires the / delimiters. The only reason Perl, JS, etc. have them is that they allow regex literals, which PHP doesn't.