"Deprecated: Function ereg_replace() is deprecated in" Php 5.3

Hello,

 I have following line was working well in php 5.2 but not in 5.3. Is it possible to fix it?

      
$q = ereg_replace("S", "s", $q);

Open in new window

mescalinAsked:
Who is Participating?
 
Beverley PortlockCommented:
One point that has not been mentioned is this - just because a function is deprecated does not mean that it does not work. ereg_replace is fine in version 5.3

Deprecated means it will be removed in a FUTURE version so you should not write any new software using it, but it will still work in the current version. You can suppress the error by changing settings in php.ini.
0
 
wkcarlsonCommented:
Try using preg_match.
0
 
Marco GasiFreelancerCommented:
You have to use preg_replace instead.

$q = preg_replace("S", "s", $q);
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
dr_linuxCommented:
In your case you can use str_replace instead.
0
 
Marco GasiFreelancerCommented:
Here you find info about preg_replace function: http://it.php.net/manual/en/function.preg-replace.php

Cheers
0
 
pius_babbunCommented:
"If you upgraded to PHP 5.3, chances are high you’re going to run into a few warnings or deprecated function messages.
An example is the ereg family of functions, which are gone for good, as they were slower and felt less familiar than the alternative Perl-compatible preg family."

http://devthought.com/2009/06/09/fix-ereg-is-deprecated-errors-in-php-53/


Hope this helps you
0
 
Marco GasiFreelancerCommented:
Oh, yeah, pius_babbun is rigth: I forgot to mention to add delimiters: $q = preg_replace("/S/", "s", $q);

I'm sorry. :-)
0
 
Ray PaseurCommented:
You can use error_reporting(E_ALL ^ E_DEPRECATED) to suppress the auto-annoyance messages.  However you really want to do a code scan and remove the ereg() in favor of the corresponding preg() functions.  And as a practical matter you do not need any regular expression to replace one character with another.  Instead of REGEX you can use this to mung the contents of $q:

$q = str_replace("S", "s", $q);
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.