PHP Remove all non-keyboard characters from string

by Subramanian 2013-07-16 12:49:45

PHP Remove all non-keyboard characters from string.

preg_replace('/[^(x20-x7F)]*/','', $text);


In the above function, "/[^(x20-x7F)]*/" is used to identify the non keyboard characters.

For Ex:

$text="GvÄÖÜSubhÂÂu"; //ÄÖÜ and ÂÂ are the non keyboard char. we need to remove it.

echo preg_replace('/[^(x20-x7F)]*/','', $text);


Output is
: GvSubhu .

and you can replace any char instead of non keyboard char, like,

echo preg_replace('/[^(x20-x7F)]*/','-', $text);


It will return
: Gv-Subh-u .
893
like
0
dislike
0
mail
flag

You must LOGIN to add comments