小白教程
所有教程
关于
Search
172.70.130.161
172.70.130.161
参数设置
贡献
退出
操作
编辑
移动
保护
信息
历史
删除
查看“Php preg quote”的源代码
本页内容
上一节:
Php_preg_match
下一节:
Php_preg_replace_callback_array
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE:preg_quote}}[[Category:PHP正则表达式(PCRE)|6]] = PHP preg_quote() 函数 = [[:Category:PHP正则表达式(PCRE)]] preg_last_error 函数用于转义正则表达式字符。 === 语法 === <sample title="" desc="" lang="php" hererun="1"> string preg_quote ( string $str [, string $delimiter = NULL ] ) </sample> preg_quote() 需要参数 str 并向其中 每个正则表达式语法中的字符前增加一个反斜线。 这通常用于你有一些运行时字符串 需要作为正则表达式进行匹配的时候。 正则表达式特殊字符有: . \ + * ? [ ^ ] $ ( ) { } = ! | : - 参数说明: * $str: 输入字符串。 * $delimiter: 如果指定了可选参数 delimiter,它也会被转义。这通常用于 转义 PCRE 函数使用的分隔符。 / 是最通用的分隔符。 === 返回值 === 返回转义后的字符串。 == == 实例 1 == <sample title="" desc="" lang="php" hererun="1"> <?php $keywords = '$40 for a g3/400'; $keywords = preg_quote($keywords, '/'); echo $keywords; ?> </sample> 执行结果转义了 $ 和 / 特殊字符,如下所示: <sample title="" desc="" lang="php" hererun="1"> 返回 \$40 for a g3\/400 </sample> == 将文本中的单词替换为斜体 == <sample title="" desc="" lang="php" hererun="1"> <?php //在这个例子中,preg_quote($word) 用于保持星号原文涵义,使其不使用正则表达式中的特殊语义。 $textbody = "This book is *very* difficult to find."; $word = "*very*"; $textbody = preg_replace ("/" . preg_quote($word) . "/", "<i>" . $word . "</i>", $textbody); echo $textbody; ?> </sample> 执行结果如下所示: <sample title="" desc="" lang="php" hererun="1"> This book is <i>*very*</i> difficult to find. </sample> [[:Category:PHP正则表达式(PCRE)]]
返回至“
Php preg quote
”。
上一节:
Php_preg_match
下一节:
Php_preg_replace_callback_array