Solved

how can I fix it php

Posted on 2011-03-17
5
333 Views
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
0
Comment
Question by:teera
  • 3
5 Comments
 
LVL 36

Expert Comment

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

Expert Comment

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

Accepted Solution

by:
Loganathan Natarajan earned 167 total points
ID: 35154270
0
 
LVL 2

Assisted Solution

by:sylenix
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().

Sample:
<?php 
$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.

Sample:
<?php
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.
0
 
LVL 4

Assisted Solution

by:max-hb
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(...)

CU
 maxhb
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

832 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