Fix `ereg is deprecated` errors in PHP 5.3

While helping someone making a php site, I ran into some old codes using ereg

To get rid of the deprecated warnings replace ereg with preg

Fix ‘ereg is deprecated’ errors in PHP 5.3

However, it didn’t quite work for me

It had something to do with some symbols being treated as delimiters when they shouldn’t be.

For some reason, the method described on that site did not fix it the issue (wrap the patterns with //)

What I ended up doing was to wrap it with

ie. ereg(“‘[-A-Za-z0-9+&@#/%?=~_|!:,.;]*[-A-Za-z0-9+&@#/%=~_|]?(/.*)?$'”, $text)
preg_match(“[-A-Za-z0-9+&@#/%?=~_|!:,.;]*[-A-Za-z0-9+&@#/%=~_|]?(/.*)?$“, $text)


ereg_replace(“([ \t\r\n])+”, “”, $text);
preg_replace(“([ \t\r\n])+“, “”, $text);


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s