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


 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

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Try using preg_match.
Marco GasiFreelancerCommented:
You have to use preg_replace instead.

$q = preg_replace("S", "s", $q);
In your case you can use str_replace instead.
Exploring SQL Server 2016: Fundamentals

Learn the fundamentals of Microsoft SQL Server, a relational database management system that stores and retrieves data when requested by other software applications.

Marco GasiFreelancerCommented:
Here you find info about preg_replace function: http://it.php.net/manual/en/function.preg-replace.php

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


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

I'm sorry. :-)
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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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);
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.