Home  >  Article  >  Backend Development  >  PHP escape regular expression characters: preg_quote_PHP tutorial

PHP escape regular expression characters: preg_quote_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:08:24801browse

PHP escapes regular expression characters: preg_quote

preg_quote — escapes regular expression characters

string preg_quote ( string $str [, string $delimiter = NULL ] )

preg_quote() takes the parameter str and adds a backslash before each character in the regular expression syntax. This is usually used when you have some runtime strings that need to be matched as regular expressions.

Regular expression special characters are: . + * ? [ ^ ] $ ( ) { } = ! < > | : -

Parameters

str

Input string

delimiter

If the optional parameter delimiter is specified, it will also be escaped. This is usually used to escape the delimiter used by the PCRE function. / is the most common delimiter.

Return value

Returns the escaped string.

preg_quote() example

$keywords = '$40 for a g3/400';
$keywords = preg_quote($keywords, '/');
echo $keywords; // Return $40 for a g3/400
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/951492.htmlTechArticlePHP escape regular expression characters: preg_quote preg_quote escape regular expression string preg_quote ( string $str [, string $delimiter = NULL ] ) preg_quote() requires the parameter str and passes it...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn