PHP Regular filter method for special characters

Source: Internet
Author: User
Tags php class php form php form submit
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

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.