|
Search:
Advanced search
|
Browse by category:
|
Contact Us |
Regular Expression to Escape all Illegal (non alphanumeric) Characters Except a space |
|||||
I created the following functions which I found to be the easiest way to escape all illegal characters.
To escape all illegal (non alphanumeric) characters except a white space. <?php function stripChars($string) { $new_string=trim(ereg_replace("[^a-zA-Z0-9[:space:]]", "", $string)); return $new_string; } $result=stripChars("This !is__ a@ test&") echo $result; ?> The above would display "This is a test" To Escape All characters except alphanumeric and an underscore ereg_replace("[^a-zA-Z0-9_]", "", $string)); To Escape All characters except alphanumeric and an underscore and a dot (period) ereg_replace("[^a-zA-Z0-9_.]", "", $string)); To Escape All characters except numeric and an underscore and a dot (period) ereg_replace("[^0-9_.]", "", $string)); |
|||||
Powered by
KBPublisher (Knowledge base software)