Fix `ereg is deprecated` errors in PHP 5.3
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
ereg('.([^.]*$)', $this->file_src_name, $extension);
preg_match('/.([^.]*$)/', $this->file_src_name, $extension);
Notice that I wrapped the pattern (
/ /, which are RegExp delimiters. If you find yourself escaping
/ too much (for an URL for example), you might want to use the
# delimiter instead.
$this->file_dst_name_body = ereg_replace('[^A-Za-z0-9_]', '', $this->file_dst_name_body);
$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
i after the delimiter:
eregi('.([^.]*$)', $this->file_src_name, $extension);
preg_match('/.([^.]*$)/i', $this->file_src_name, $extension);
Incoming search terms:
- fix ereg is deprecated errors in php 5 3 (2)
- centos php ereg (1)
- deprecated function eregi() is deprecated direct admin (1)
- deprecated function ereg_replace() is deprecated directadmin (1)
- Deprecated: Function ereg() is deprecated debian (1)
- fix `ereg is deprecated` errors in php 5 3 (1)
- how to fix asterisknow php53 (1)
- php deprecated linux sed replace (1)