1. Welcome to PHCorner Forums. Take a moment to Sign up and gain unlimited access and extra privileges that guests are not entitled to, such as:

    All that and more! Registration is quick, simple and absolutely free. Join our community today!

PHP Fix `ereg, eregi, ereg_replace is deprecated` errors in php 5.3

Discussion started by Draft, Mar 9, 2013.

Thread Status:
Not open for further replies.
  1. Draft

    Draft Administrator Staff Member Administrator

    If you upgraded to PHP 5.3, chances are high you’re going to run into a few warnings or deprecated function messages.
    An example is the ereg family of functions, which are gone for good, as they were slower and felt less familiar than the alternative Perl-compatible preg family.
    To migrate ereg():
    1. ereg('\.([^\.]*$)', $this->file_src_name, $extension);
    1. preg_match('/\.([^\.]*$)/', $this->file_src_name, $extension);
    Notice that I wrapped the pattern (\.([^\.]*$)) around / /, which are RegExp delimiters. If you find yourself escaping / too much (for an URL for example), you might want to use the # delimiter instead.
    To migrate ereg_replace():
    1. $this->file_dst_name_body = ereg_replace('[^A-Za-z0-9_]', '', $this->file_dst_name_body);
    1. $this->file_dst_name_body = preg_replace('/[^A-Za-z0-9_]/', '', $this->file_dst_name_body);
    Again, I just added delimiters to the pattern.
    If you are using eregi functions (which are the case-insensitive version of ereg), you’ll notice there’re no equivalent pregi functions. This is because this functionality is handled by RegExp modifiers.
    Basically, to make the pattern match characters in a case-insensitive way, append iafter the delimiter:
    1. eregi('\.([^\.]*$)', $this->file_src_name, $extension);
    1. preg_match('/\.([^\.]*$)/i', $this->file_src_name, $extension);
    YOVICPAW and king pio like this.
  2. Draft

    Draft Administrator Staff Member Administrator

    Thanks devthought!
Thread Status:
Not open for further replies.
  1. PHCorner uses cookies to help personalise content and tailor your experience. By continuing to use this site, you are consenting to our use of cookies. Accept Learn More
    Dismiss Notice