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

6

34

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.

Ritualist answered 28/6, 2010 at 13:41 Comment(1)
A Reference Question is: How can I convert ereg expressions to preg in PHP?Colombo
E
45

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).

Eyesore answered 28/6, 2010 at 13:43 Comment(0)
H
37
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 );
Haplology answered 18/8, 2011 at 5:42 Comment(0)
M
6

change the call to ereg_replace to use preg_replace instead

Moskva answered 28/6, 2010 at 13:44 Comment(0)
G
4

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.

Guarnerius answered 28/6, 2010 at 13:44 Comment(0)
R
3

IIRC they suggest using the preg_ functions instead (in this case, preg_replace).

Robles answered 28/6, 2010 at 13:43 Comment(0)
S
3

Here is more information regarding replacing ereg_replace with preg_replace

Sclar answered 28/6, 2010 at 13:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.