Function ereg_replace() is deprecated - How to clear this bug?
Switch to preg_replace
Docs and update the expression to use preg syntax (PCRE) instead of ereg syntax (POSIX) where there are differencesDocs (just as it says to do in the manual for ereg_replace
Docs).
Deprecated: Function ereg_replace() is deprecated
The function ereg_replace()
is deprecated, that means that it is no longer supported by PHP by a particular reason (can be security or performance reasons, for example).
Instead, use preg_replace()
. You also need to replace the regular expression string
[ ]{2,}
to
/[ ]{2,}/
Read more about pattern delimiters.
Replacing deprecated ereg_replace() with preg_replace() did not work
You seem to be missing markers around the regular expression. Try this instead (note the slashes around the pattern).
$string = "This is some text and numbers 12345 and symbols !$%^&";
$new_string = preg_replace("/[^A-Za-z0-9 (),.]/", "", $string);
echo "Old string is: ".$string."<br />New string is: ".$new_string;
You can use any character for the markers as long as the same one is found on both sides. Very useful if your pattern is matching /
characters. So this is also valid:
$string = "This is some text and numbers 12345 and symbols !$%^&";
$new_string = preg_replace("~[^A-Za-z0-9 (),.]~", "", $string);
echo "Old string is: ".$string."<br />New string is: ".$new_string;
php - deprecated function ereg_replace() is deprecated in php
ereg_replace
deprecated. Use preg_replace
like this:
$string = preg_replace('/ \+/', ' ', trim($string));
That is important / \+/
pattern. Space
and plus(+)
Related Topics
What Is the Maximum Size of an Array in PHP
PHP File Upload Error Tmp_Name Is Empty
Why PHP Variables Start with a $ Sign Symbol
Pass a Percent (%) Sign in a Url and Get Exact Value of It Using PHP
Get Variables from the Outside, Inside a Function in PHP
Store_Result() and Get_Result() in MySQL Returns False
PHP Date Returning Wrong Month on Subtracting One Month
Is MySQLi Extension Enabled in This PHP Configuration
Warning: Date() Expects Parameter 2 to Be Long, String Given In
How to Pass Multiple Variables Across Multiple Pages