The following PHP program replaces the symbols !£$%^& with nulls
<?php
$string = "This is some text and numbers 12345 and symbols !£$%^&";
$new_string = ereg_replace("[^A-Za-z0-9 (),.]", "", $string);
echo "Old string is: ".$string."<br />New string is: ".$new_string;
?>
Output:
Old string is: This is some text and numbers 12345 and symbols !£$%^&
New string is: This is some text and numbers 12345 and symbols
But, I have learned that the function ereg_replace() has been deprecated and that I should use the function preg_replace() instead. I made the substitution like so:
<?php
$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;
?>
but got the wrong output:
Old string is: This is some text and numbers 12345 and symbols !£$%^& New string is: This is some text and numbers 12345 and symbols !£$%^&
What did I do wrong? How do I fix it?