2011-12-08 8 views
-4
私は、次の試み

PHPのPCRE正規表現のコンパイルエラー

$searchText = preg_quote($searchText, '/'); 
$remarks = preg_replace('/'.$searchText.'/i', '<span class="searchText">$0</span>', $remarks); 

I取得するには、次のエラーメッセージ:

で0

Iの避難所をオフセットが大きすぎる

正規表現」これが何を意味しているのか、それをどうやって得ているのか、それをどう修正するのかという手がかりを得ました。 私はこのエラーメッセージをGoogleに書き込むと、私が見つけられないphp.ini設定への参照を取得します。

+2

それで '$ searchText'には何がありますか? – nickb

+3

'too large'は、現代的な言語ではっきりとしたメッセージと共通のフレーズです。あなたは手がかりを得ていませんか? –

+0

あなたの正規表現は大きすぎます。正規表現が何であるかを見ることなく、私たちはあなたを助けることができません。 –

答えて

3

正規表現のサイズ制限は65539です(はい、65536ではありません)。あなたは限界を超えています。

はこちらをご覧ください:http://www.pcre.org/pcre.txt

SIZE AND OTHER LIMITATIONS 

     There are some size limitations in PCRE but it is hoped that they will 
     never in practice be relevant. 

     The maximum length of a compiled pattern is 65539 (sic) bytes if PCRE 
     is compiled with the default internal linkage size of 2. If you want to 
     process regular expressions that are truly enormous, you can compile 
     PCRE with an internal linkage size of 3 or 4 (see the README file in 
     the source distribution and the pcrebuild documentation for details). 
     In these cases the limit is substantially larger. However, the speed 
     of execution is slower. 
+1

私の場合、「実際には決して関連性がないことが期待されます」という文章は「あなたが何か間違っていることを意味します」 – nickb

1

以前の質問から、あなたがのためにユーザーを検索、その単語を強調しようとしているように見えます。そうであれば、正規表現は必要ありません。

$remarks = str_replace($searchText, '<span class="searchText">' . $searchText . '</span>', $remarks); 

単語内の文字列が強調表示されることに注意してください。あなたが言葉全体にマッチするだけなら、私は自分の答えを更新することができます。

+0

私がpreg_replace()をしたのは、表示されるテキストの大文字と小文字を区別せずに大文字小文字を区別しません。 str_replace()をstr_ireplace()に変更して、ユーザーがそのようなテキストとして入力した場合に関係なくテキストを照合し強調表示できますが、ユーザーに返された結果の大文字と小文字はすべてユーザーが入力したものです。 – user39653