Need help removing un-wanted characters from your php text form strings. Here's
how to strip a string of all symbols and characters other than alphanumeric
letters and numbers from your file or database. This code will delete any
non-alphanumeric characters specified between the brackets, and then output/return
the clean version.
The code
<?php
$string = "Here! is some text, and numbers 12345, and symbols !£$%^&";
$new_string = preg_replace("/[^a-zA-Z0-9s]/", "", $string);
echo $new_string
?>
The code should return this:
Here is some text and numbers 12345 and symbols
One more thing. If you don't like to keep the blank white space in your
text just reformat the preg_replace by removing the "s" whitespace character
types. This is good for use with user names and passwords. The code would now
look something like this:
Hereissometextandnumbers12345andsymbols
NewSourceMedia is providing links to these listings as
a courtesy, and makes no representations regarding the content or
any information related thereto. Any questions, complaints or claims
regarding the downloaded content or details must be directed to the appropriate
publisher. We do not encourage or condone the use of any
software in violation of applicable laws.