Skip to content

Instantly share code, notes, and snippets.

@zmiftah
Created September 12, 2012 09:45
Show Gist options
  • Save zmiftah/3705591 to your computer and use it in GitHub Desktop.
Save zmiftah/3705591 to your computer and use it in GitHub Desktop.
PHP: ereg function Deprecated
<?php
//
// Source: http://www.devthought.com/2009/06/09/fix-ereg-is-deprecated-errors-in-php-53/
//
// To migrate ereg():
ereg('\.([^\.]*$)', $this->file_src_name, $extension);
// becomes
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.
//Basically, to make the pattern match characters in a case-insensitive way, append i after the delimiter:
eregi('\.([^\.]*$)', $this->file_src_name, $extension);
// becomes
preg_match('/\.([^\.]*$)/i', $this->file_src_name, $extension);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment