Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Function ereg_replace() is deprecated - How to clear this bug? [duplicate]

I have written following PHP code:

$input="menu=1&type=0&";

print $input."<hr>".ereg_replace('/&/', ':::', $input);

After running above code, it gives following warning,

Deprecated: Function ereg_replace() is deprecated

How can I resolve this warning.

like image 476
Pradip Avatar asked Jun 28 '10 13:06

Pradip


4 Answers

Switch to preg_replaceDocs and update the expression to use preg syntax (PCRE) instead of ereg syntax (POSIX) where there are differencesDocs (just as it says to do in the manual for ereg_replaceDocs).

like image 134
Quentin Avatar answered Oct 31 '22 18:10

Quentin


print $input."<hr>".ereg_replace('/&/', ':::', $input);

becomes

print $input."<hr>".preg_replace('/&/', ':::', $input);

More example :

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

is changed to

$mytext = preg_replace('/[^A-Za-z0-9_]/', '', $mytext );
like image 45
Krishna Tripathee Avatar answered Oct 31 '22 19:10

Krishna Tripathee


change the call to ereg_replace to use preg_replace instead

like image 6
Mark Baker Avatar answered Oct 31 '22 18:10

Mark Baker


http://php.net/ereg_replace says:

Note: As of PHP 5.3.0, the regex extension is deprecated in favor of the PCRE extension.

Thus, preg_replace is in every way better choice. Note there are some differences in pattern syntax though.

like image 4
Amadan Avatar answered Oct 31 '22 19:10

Amadan