Hello friends. At some point we need to filter our strings and remove some unwanted characters from the string for some purpose. It is quite easy to do this with regular expressions.
Php built-in function preg_replace() can be used to remove special characters from a string. It takes 3 parameters and its syntax is
Php built-in function preg_replace() can be used to remove special characters from a string. It takes 3 parameters and its syntax is
$output = preg_replace(pattern, replacWith, string);Remove all characters except alphabets and digits use this.
$output = preg_replace('/[^a-zA-Z0-9]/s', '', $string);
Remove all ascii characters from the string use this.
$output=preg_replace('/[^(\x20-\x7f)]*/s','',$string);
Posting Komentar