how can I fix it php

Posted on 2011-03-17
Last Modified: 2012-05-11

Deprecated: Function ereg_replace() is deprecated in C:\wamp\www\mayor\ageyearinfo.php(1) : eval()'d code on line 1
Question by:teera
  • 3
LVL 36

Expert Comment

by:Loganathan Natarajan
ID: 35154263
what is your php version?
LVL 36

Expert Comment

by:Loganathan Natarajan
ID: 35154266
you have to use, preg_replace()
LVL 36

Accepted Solution

Loganathan Natarajan earned 167 total points
ID: 35154270

Assisted Solution

sylenix earned 167 total points
ID: 35154432
ereg_replace() is a search and replace function but has been deprecated as of PHP v5.3.0. preg_replace() is a much faster alternative to ereg_replace().

$lookFor = 'PRICE'; 
$replacement = '$100'; 

echo $replacement.'<br />'; 
// will display 
// $100 

echo preg_replace('/'.$lookFor.'/', $replacement, $text).'<br />'; 
// Will display 
// The price is 0  

echo str_replace($lookFor, $replacement, $text).'<br />'; 
// Will display 
// The price is $100 

Open in new window

you can also use str_replace() for simple search & replace function.

echo str_replace("world","Peter","Hello world!");
// Will display
// Hello Peter!

Open in new window

by the way, this function is case-sensitive. use str_ireplace() for case-insensitive replace.

Assisted Solution

max-hb earned 166 total points
ID: 35155051
Deprecated functions are still working but will be turned off in future php versions.

So you have several options:
a) Change from ereg_replace() to preg_replace() (that will work with coming php versions)
b) use error_reporting(A_ALL & ~E_DEPRECATED) to turn off deprecation warnings
c) Place a @-symbol  in front of all deprecated function calls, like @ereg_replace(...)


Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now