views:

25

answers:

1

I have this line in one of my scripts and its throwing a deprecated error.

 eregi_replace( '\.([a-z]{3,4})$', "-{$width}x{$height}.\\1", $src );

Can someone show me how to turn this into preg_replace and tell me why and which bits of it need to change so I can learn for future changes? I have had a go myself but where this bit of code is means its really hard to test!!

Is it as simple as purely replacing the eregi_replace with preg_replace?

I hate regular expressions :)

+3  A: 

You need delimiters like / and the i modifier:

/\.([a-z]{3,4})$/i

So:

preg_replace('/\.([a-z]{3,4})$/i', "-{$width}x{$height}.\\1", $src);

See this manual page for the differences between POSIX ERE and PCRE.

Gumbo
Thank you for taking the time to reply, need to work out how to test it now :)
Paul M