homepage Welcome to WebmasterWorld Guest from 54.211.73.232
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Errors eregi replace and ereg replace are deprecated
New to php and struggling with this error message
arthur22



 
Msg#: 4455335 posted 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!

 

CoursesWeb



 
Msg#: 4455335 posted 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.

arthur22



 
Msg#: 4455335 posted 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?

g1smd

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4455335 posted 7:39 pm on May 20, 2012 (gmt 0)

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.

arthur22



 
Msg#: 4455335 posted 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.

rocknbil

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



 
Msg#: 4455335 posted 4:14 pm on May 21, 2012 (gmt 0)

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)

g1smd

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4455335 posted 6:42 pm on May 21, 2012 (gmt 0)

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved