?
Solved

how can I fix it php

Posted on 2011-03-17
5
Medium Priority
?
340 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 668 total points
ID: 35154270
0
 
LVL 2

Assisted Solution

by:sylenix
sylenix earned 668 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 664 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
This article discusses how to implement server side field validation and display customized error messages to the client.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

770 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