Asked  2 Years ago    Answers:  5   Viewed   291 times

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.

 Answers

5

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

Friday, December 9, 2022
5

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

you can use preg_match().

Friday, August 26, 2022
 
3

I think you want preg_split.

list($year, $month, $day, $hour, $min, $sec) = preg_split('/[: -]/', $post_timestamp);
Wednesday, December 14, 2022
3

Use preg_replace instead, just add delimiters.

$row[$j] = preg_replace("#n#", "\n", $row[$j]);
Wednesday, December 14, 2022
2

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(("|')(.+)("|'),/',
                            "preg_match('/$2/',",
                            $content);
    file_put_contents($path, $content);
}

I hope it helps.

Wednesday, August 10, 2022
 
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :
 

Browse Other Code Languages