Eregi to preg_replace change for php 5.3 compatibility
I have this line in one of my scripts and its throwing a deprec开发者_运维百科ated 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 :)
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.
精彩评论