PHP escape regular expression characters: preg_quote_PHP tutorial

WBOY
Release: 2016-07-13 10:08:24
Original
810 people have browsed it

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...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!