Solved

how can I fix it php

Posted on 2011-03-17
5
329 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
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…
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 create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

896 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

18 Experts available now in Live!

Get 1:1 Help Now