I have 80 points for filtering Special characters .. I have encountered a problem. when submitting a form, filter out the submitted content with special characters such :~! @ # $ % ^ & Amp; * () _ + & nbsp ;.. for example, I have submitted the following content: Life * & amp;) can) (_ how to filter out more beautiful: Life can be more beautiful. My practice is: $ str = str_replace (for filtering Special characters... I have 80 points ..
I have encountered a problem. when submitting a form, filter out the submitted content with special characters such :~! @ # $ % ^ & * () _ + ..
If I submit a message: Life * &) can) (_ more beautiful
How to filter out: Life can be more beautiful.
My approach is:
$ Str = str_replace ("&", "", $ str );
$ Str = str_replace (">", "", $ str );
$ Str = str_replace ("<", "", $ str );
$ Str = str_replace ("=", "", $ str );
$ Str = str_replace ("(", "", $ str );
$ Str = str_replace (")", "", $ str );
$ Str = str_replace ("[", "", $ str );
$ Str = str_replace ("]", "", $ str );
$ Str = str_replace (".", "", $ str );
$ Str = str_replace ("*", "", $ str );
$ Str = str_replace ("#", "", $ str );
$ Str = str_replace ("$", "", $ str );
$ Str = str_replace ("@", "", $ str );
$ Str = str_replace ("-", "", $ str );
$ Str = str_replace ("+", "", $ str );
$ Str = str_replace ("&", "", $ str );
$ Str = str_replace ("! "," ", $ Str );
$ Str = str_replace ("~ "," ", $ Str );
$ Str = str_replace ("^", "", $ str );
$ Str = str_replace ("%", "", $ str );
$ Str = str_replace ("'", "", $ str );
$ Str = str_replace ("\" "," ", $ str );
Is there a simpler method .. Please advise .. I have 80 points .. Share:
------ Solution --------------------
Reference:
Why: $ str = preg_replace ("['~! @ # $ % ^ & * () + =
------ Solution --------------------
{} ':;', // [//]. <> /?~! @ # ¥ % ...... & * () -- +
------ Solution --------------------
{} [] ';: "'., ,?] ",'', $ Str); can't you write it like this?
1. the biggest problem is that the regular expression does not have a boundary.
2. escape is not // But \, and the double quotation marks are \\
3.
------ Solution --------------------
Is regarded as or selected
4. Are there double quotation marks in double quotation marks?
......
------ Solution --------------------
$ P = str_split ("& ><= () []. * # $ @-+ &! ~ ^ % '\"_");
$ S = 'life * &) can) (_ more beautiful ';
Echo str_replace ($ p, '', $ s );Life can be more beautiful
------ Solution --------------------
Reference:
Thank you for your advice. I just don't know whether the character in the full-width corner can be used .. I will try
Use the following function to change the width.
function mb_str_split( $string, $encoding='UTF-8' ) {
# Split at all position not after the start: ^