Fix ereg is deprecated errors in PHP 5.3+

When you upgrad to PHP 5.3+, you will run into a ereg deprecated function messages.

You need to use preg instead of ereg.

Ereg example

    eregi('\.([^\.]*$)', $from, $to);

can replace with preg_match

    preg_match('#\.([^\.]*$)#i', $from, $to);

notice the hashmark, which are RegExp delimiters!
Look the i modifier! If you delete it, you’ll get the ereg() method

ereg_replace()

    $var = ereg_replace('[^A-Za-z0-9_]', '', $var);

becomes preg_replace()

    $var = preg_replace('#[^A-Za-z0-9_]#', '', $var);

Not too complicated, right? Again: #

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.