PHP: Deprecated: The ereg extension is deprecated and will be removed in the future:

What can you do?
replace ereg() with @ereg()
or
set error reporting in php.ini to error_reporting = E_ALL ^ E_DEPRECATED
to eliminate the messages, but eventually you will have to port
or
port to preg_match()

you should know 4 main things to port ereg patterns to preg_match:

1. Add delimiters(/): ‘pattern’ => ‘/pattern/’

ereg(‘A-Z0-9a-z’,’string’); becomes preg_match(‘/A-Z0-9a-z/’,’string’);

eregi(‘pattern’,’string’); becomes preg_match (‘/pattern/i’,’string’);

2. Escape delimiter if it is a part of the pattern: ‘patt/ern’ => ‘/patt\/ern/’

Achieve it programmatically in following way:
$old_pattern = ‘<div>.+</div>’;
$new_pattern = ‘/’ . addcslashes($ereg_pattern, ‘/’) . ‘/’;

3. eregi(case-insensitive matching): ‘pattern’ => ‘/pattern/i’ So, if you are using eregi function for case insenstive matching, just add ‘i’ in the end of new pattern(‘/pattern/’).

4. ASCII values: In ereg, if you use number in the pattern, it is assumed that you are referring to the ASCII of a character. But in preg, number is not treated as ASCII value. So, if your pattern contain ASCII value in the ereg expression(for example: new line, tabs etc) then convert it to hexadecimal and prefix it with \x.

Example: 9(tab) becomes \x9 or alternatively use \t.

Leave a Reply

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