Asked  7 Months ago    Answers:  5   Viewed   74 times

I have written following PHP code:


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.



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

Wednesday, March 31, 2021
answered 7 Months ago

eregi() function has been DEPRECATED as of PHP 5.3.0. Relying on this feature is highly discouraged.

you can use preg_match().

Saturday, May 29, 2021
answered 5 Months ago

I think you want preg_split.

list($year, $month, $day, $hour, $min, $sec) = preg_split('/[: -]/', $post_timestamp);
Friday, June 11, 2021
answered 5 Months ago

Use preg_replace instead, just add delimiters.

$row[$j] = preg_replace("#n#", "\n", $row[$j]);
Saturday, July 31, 2021
answered 3 Months ago

You must use preg_match instead of ereg because the last one is deprecated.

Replacing it is not a big deal:

ereg( "[][{}()*+?.\^$|]", $_REQUEST['name'] )

will become:

preg_match( "/[][{}()*+?.\^$|]/", $_REQUEST['name'] )

p.s. I had to modify more than one hundred files while I was porting my old project to PHP 5.3 to avoid manually modifying I've used following script to do it for me:

function replaceEregWithPregMatch($path) {
    $content = file_get_contents($path);
    $content = preg_replace('/ereg(("|')(.+)("|'),/',
    file_put_contents($path, $content);

I hope it helps.

Monday, August 23, 2021
Aniket Thakur
answered 2 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :