This article introduces a way to filter special characters in PHP programming, with the need to refer to a friend. Filter special characters with regular expressions in PHP, you can use the function preg_quote:string preg_quote (string $str [, String $delimiter]) The finds the special characters that appear in the $STR string that are part of the regular expression and adds a backslash before the special character. The can provide an optional $delimiter string parameter as a new escape character set. The special characters of the Regular expression include:. \ + *? [ ^ ] $ ( ) { } = ! < > | : 。 The String addslashes (String $str) Adds backslashes on special characters in the string to be written to the database, with single quotation marks ('), double quotation marks ("), a backslash (\), and a null (null character). When php.ini instruction MAGIC_QUOTE_GPC = ON, it means that special characters in the data are automatically prefixed with a backslash when the data is written to the database. You can use the GET_MAGIC_QUOTES_GPC () function to detect whether MAGIC_QUOTE_GPC is turned on. PHP's official recommendation is to set the value of MAGIC_QUOTE_GPC to off because the opening of this configuration may pose a security problem, preferably by manually processing the data written to the database. The String addcslashes (String $str, String $charlist) Escapes the string in the style of the C language. The $charlist parameter is provided to the function with a character set that needs to be escaped, that is, you can give the character you want to escape to the $charlist string parameter. If you want to escape all English letters from A to Z, you can use a. Write parameters in the form Z. When using this function, you should pay attention to the predefined escape sequences in the C language. PHP Filter Special characters utility function php form Submit special character filter method HTML special character filter PHP class URL link special character escape method php special character escape detailed PHP filter parameters special characters anti-injection PHP Methods for filtering illegal and special strings examples of PHP special character handling functions |