簡體   English   中英

preg_match_all的問題:編譯失敗,沒有匹配的括號

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM