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)
becomes
preg_match(“[-A-Za-z0-9+&@#/%?=~_|!:,.;]*[-A-Za-z0-9+&@#/%=~_|]?(/.*)?$“, $text)

and

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

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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