Home >php教程 >php手册 >PHP 转义正则表达式字符: preg_quote

PHP 转义正则表达式字符: preg_quote

WBOY
WBOYOriginal
2016-06-13 09:15:551349browse

PHP 转义正则表达式字符: preg_quote

 preg_quote — 转义正则表达式字符

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

preg_quote()需要参数str并向其中 每个正则表达式语法中的字符前增加一个反斜线. 这通常用于你有一些运行时字符串 需要作为正则表达式进行匹配的时候.

正则表达式特殊字符有: . \ + * ? [ ^ ] $ ( ) { } = ! | : -

参数

str

输入字符串

delimiter

如果指定了可选参数delimiter, 它也会被转义. 这通常用于 转义PCRE函数使用的分隔符. /是最通用的分隔符.

 

返回值

返回转义后的字符串.

preg_quote()示例

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

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