Table of Contents

Syntax

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.

What it Does

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.

Example

// Escape special pattern characters using "quotemeta"
$pattern = quotemeta('not\.in*?som(eone)e[lse]s^back+yard');
echo 'Quoted Pattern: ' . htmlspecialchars($pattern) . '<br>';
 
quotemeta.txt · Last modified: 2011/02/18 17:06 by orvado
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki