Welcome to WebmasterWorld Guest from 54.227.214.52

Forum Moderators: coopster & jatar k

Errors eregi replace and ereg replace are deprecated

New to php and struggling with this error message

   
3:33 pm on May 19, 2012 (gmt 0)



I've just taken over a site written in php and I'm struggling with this error message:

Deprecated: Function eregi_replace() is deprecated in /home/content/myserverdetails/myfile.php on line 203


The code is from a program that sends out ecards. The errors relate to the following lines:


$output = eregi_replace("\"",""",$output);

$this->send_text = ereg_replace('"','"',$postcard_text);

$this->card_text = ereg_replace('"','"',$postcard_text);


Is is possible to tell just from that code what I need to change? I'm running php 5.3. I'm trying to learn the basics of php but I would really appreciate any pointers to help get rid of this error. Thanks!
3:54 pm on May 19, 2012 (gmt 0)



Hi,
As the error says, eregi_replace(0 is deprecated, no more used in php.
Use preg_replace() instead. See on php.net about this function.
7:32 pm on May 20, 2012 (gmt 0)



I've tried just changing the ereg_replace bit to preg_replace for the second and third lines mentioned above, but then I get this error instead:

Warning: preg_replace() [function.preg-replace]: No ending delimiter '/' found in /home/content/myserver/index.php on line 840

Warning: preg_replace() [function.preg-replace]: No ending delimiter '&' found in /home/content/myserverindex.php on line 841

Any ideas?
7:39 pm on May 20, 2012 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



Yes, you need to add the / delimiter to the beginning and end of the RegEx pattern as explain in the PHP manual.

If the pattern contains a / already, use # for the two delimiters instead.
3:59 pm on May 21, 2012 (gmt 0)



Thank for the replies, I seem to have managed to fix it now by updating to preg_replace. I have noticed that there's still two instances of the old ereg_replace left in the code that don't seem to be throwing an error. Will the error only show for certain examples? Seems a bit odd that those other instances seem OK.
4:14 pm on May 21, 2012 (gmt 0)

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member



It's probably a condition that hasn't been called by your program.

if ($is_logged_in) {
// whatever
}

Change them all. look for eregi too (preg_match)
6:42 pm on May 21, 2012 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



Change them all. Look in every php file to be sure.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month