Solved

how can I fix it php

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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
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…
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.

696 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