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> ";?