Link to home
Start Free TrialLog in
Avatar of sabecs
sabecs

asked on

PHP error - Deprecated: Function ereg_replace() is deprecated

Hi,
I am receiving the following error message and would like to know if I should replace all occurrences of ereg_replace with preg_replace in my code and do I need to change anything else?

Deprecated: Function ereg_replace() is deprecated in /home/mywebsite/public_html/admin/website_settings.php on line 797
   
                              
$imagesml = ereg_replace ( '.jpg', '_med.jpg',  $row_view_tbl["image1"]);
$temps[$j] = ereg_replace ( '.jpg', '_sml.jpg', $temp[$j]);

Thanks in adavance for you feedback.
Avatar of Terry Woods
Terry Woods
Flag of New Zealand image

Yes, they need to be changed, but it's not as simple as changing the function name. How many occurrences do you have? It's pretty quick for me to convert them:

$imagesml = ereg_replace ( '.jpg', '_med.jpg',  $row_view_tbl["image1"]);
$imagesml = preg_replace ( '/\.jpg/', '_med.jpg',  $row_view_tbl["image1"]); #Escaped the . to treat it as a literal period rather than a wilcard


$temps[$j] = ereg_replace ( '.jpg', '_sml.jpg', $temp[$j]);
$temps[$j] = preg_replace ( '/\.jpg/', '_sml.jpg', $temp[$j]); #Escaped the . to treat it as a literal period rather than a wilcard

Note the eregi_replace function is affected too.
I am not recommending this as  along-term strategy, but you can also turn off the Deprecated messages.  That might be a good solution short term.

Add this to the top of your script:
error_reporting(E_ALL ^ E_DEPRECATED);

Open in new window

Since this message is occurring as a byproduct of a PHP upgrade migration, you may want to know about other PHP upgrade issues.  These articles cover a couple of the issues.
https://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_6630-Magic-Quotes-a-bad-idea-from-day-one.html
https://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_7317-Register-Globals-a-bad-idea-from-day-one.html

PHP also has migration guides on the web site.  See the pages linked from this (left sidebar).
http://us.php.net/migration54
Avatar of sabecs
sabecs

ASKER

Thanks for your feedback, I probably have about 100 occurrences throughout my website.
If I set  error_reporting to hide the messages I am assuming that the ereg_replace will still work, is that correct and if so for how long?
SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
100 occurrences doesn't take long to convert - feel free to post them.
Avatar of sabecs

ASKER

Thanks for your help, much appreciated.
I have about 100 occurrences but most are the same repeated throught the site so really I just have 5 similar ones which are shown below.

$imagesml = "/".ereg_replace ( '.jpg', '_swg.jpg',  $row_view_photos1["image1"]);
$image1 = ereg_replace ( '.jpg', '_swg.jpg',  $image1);
$imagesml1 = ereg_replace ( '.jpg', '_sml.jpg',  $row_view_tbl["image1"]);
$release = ereg_replace('^([[:digit:]]+\.[[:digit:]]+).*', '\1', $parts[2]);
$release = ereg_replace('-.*', '', $parts[2]);
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial