(no need to inform user that they have invalid characters)
Code: Select all
function english_only ($value){
return ereg_replace("[^a-zA-Z0-9\n\t\r\s!@#$%^&*()-_=+`~{}|\:;\"']", "", $value);
}
$name = english_only($_POST['name']);
//simple sql to store into DB
So the $name string might be something like 'John � Smith', and the regex replace will not work since it is reading in each character seperately. Hence I tried
Code: Select all
$name = html_entity_decode(english_only($_POST['name']));
Code: Select all
$string = "&";
echo strlen($string) // returns 5
$string = html_entity_decode($string);
echo strlen($string) // returns 1
Code: Select all
$string = "�";
echo strlen($string) // returns 8
$string = html_entity_decode($string);
echo strlen($string) // returns 8
Anyone knows why is this happening?
Thanks!