Pradip
Pradip

Reputation: 1327

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

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.

Upvotes: 34

Views: 188485

Answers (6)

Krishna Tripathee
Krishna Tripathee

Reputation: 371

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

Upvotes: 37

Quentin
Quentin

Reputation: 943556

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

Upvotes: 45

Darko Kenda
Darko Kenda

Reputation: 4960

Here is more information regarding replacing ereg_replace with preg_replace

Upvotes: 3

Amadan
Amadan

Reputation: 198314

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.

Upvotes: 4

Mark Baker
Mark Baker

Reputation: 212412

change the call to ereg_replace to use preg_replace instead

Upvotes: 6

Wevah
Wevah

Reputation: 28242

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

Upvotes: 3

Related Questions