PHP adds backslash function Quotemeta () before some predefined characters in the string

Source: Internet
Author: User

Instance

To add a backslash before a predefined character:

<?PHP$STR = "Hello World". (Can you hear me?) "; echo Quotemeta ($STR);? >

Definition and usage

The Quotemeta () function adds a backslash before some of the predefined characters in the string.

Pre-defined characters:

    • Period (.)

    • Back slash (\)

    • Plus (+)

    • asterisk (*)

    • Question mark (?)

    • square brackets ([])

    • Caret (^)

    • Dollar sign ($)

    • Parentheses (())

Tip: This function can be used to escape characters that have special meanings, such as (), [], and * in SQL.

Note: This function is binary safe.

Grammar

Quotemeta (String)

Parameter description

string is required. Specifies the string to check.

Technical details

Return value: A string that returns a reference metacharacters character.

PHP version: 4+

More examples

Example 1

Add a backslash before several predefined characters:

<?PHP$STR1 = "1 + 1 = 2"; $str 2 = "1 * 1 = 1"; $str 3 = "Could you borrow me 5$?"; $str 4 = "is not entertained?" (I am ...) "; $str 5 = "the caret [^] Looks like a hat!"; Echo Quotemeta ($str 1). " <br> "; Echo Quotemeta ($str 2)." <br> "; Echo Quotemeta ($str 3)." <br> "; Echo Quotemeta ($str 4)." <br> "; Echo Quotemeta ($str 5)." <br> ";? 

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.