[英]Issue with preg_match_all : Compilation failed unmatched parentheses
我正面臨以下警告
preg_match_all():編譯失敗:偏移量4處的括號不匹配
使用時preg_match_all
以下是代碼
preg_match_all('/' . $word . '/i', $text, $matches);
看起來在$word
上有一些特殊字符用於正則表達式語法中。 您的$word
包含以下字符之一: . \\ + * ? [ ^ ] $ ( ) { } = ! < > | : - #
. \\ + * ? [ ^ ] $ ( ) { } = ! < > | : - #
. \\ + * ? [ ^ ] $ ( ) { } = ! < > | : - #
您必須使用preg_quote
引用這些字符:
preg_match_all('/'.preg_quote($word).'/i', $text, $matches);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.