PHPプログラムに関する各種メモ書き

UTF-8を使った正規表現でエラー「this version of PCRE is not compiled with PCRE_UTF8」の場合の対応

PHPで UTF-8 を使った正規表現の命令時 ( preg_match('test/u', $str); )に

以下のようなエラー

Compilation failed: this version of PCRE is not compiled with PCRE_UTF8 support

が出ることがあります。

これは「PCREがUTF-8をサポートしていないときに出るエラーです。」

PCREのサポート状況を知るにはコマンド【pcretest -C】を実行するか、

pcretest.php を以下の内容で保存してWEBブラウザから実行します。

pcretest.php

<?php
print '<pre>';
print '<h1>実行コマンド:pcretest -C</h1>';
print ( shell_exec('pcretest -C') );
print '</pre>';
?>

これでUTF-8サポートがなければ再度PCRE, PHPをコンパイルしましょう。

レンタルサーバの場合は仕方ないので preg_match などの /u オプションを取り除いたコーディングとしましょう。



No.839
03/21 22:46

edit