string quotemeta( string $text )
(PHP 4, PHP 5)
| $text | The source string to escape pattern characters. |
|---|---|
| RETURNS | The string with special pattern characters escaped with a backslash. |
This method was originally intended for escaping characters that are commonly used in a regular expression pattern. This will excape the following characters with a backslash:
| . | Period |
|---|---|
| \ | Backslash |
| + | Plus |
| * | Asterisk |
| ? | Question Mark |
| [ | Open Bracket |
| ] | Close Bracket |
| ^ | Caret |
| ( | Open Parens |
| ) | Close Parens |
| $ | Dollar Symbol |
For a method that does a more complete job of escaping pattern characters, please check out the function preg_quote.
// Escape special pattern characters using "quotemeta" $pattern = quotemeta('not\.in*?som(eone)e[lse]s^back+yard'); echo 'Quoted Pattern: ' . htmlspecialchars($pattern) . '<br>';