勉強したことのメモ

webプログラマが勉強したことのメモ。

mPDFで「The /e modifier is …」エラー

   

pdf関連のPHPライブラリ「mPDF」を使っているページがエラーログにのっており「PHP Deprecated:  preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in」というエラー内容だった。以下に対応方法をメモ。

 

対応方法

/mpdf/includes/functions.phpの66、67行目を以下の通り書き換える。バージョンによって行数は違うかもしれない。

#以下の部分を、
#$str = preg_replace('/\&\#([0-9]+)\;/me', "code2utf('\\1',{$lo})",$str);
#$str = preg_replace('/\&\#x([0-9a-fA-F]+)\;/me', "codeHex2utf('\\1',{$lo})",$str);

#以下の通り書き換える
$str = preg_replace_callback('/\&\#([0-9]+)\;/m', function($m) use ($lo){return code2utf($m[1],$lo); }, $str);
$str = preg_replace_callback('/\&\#x([0-9a-fA-F]+)\;/m', function($m) use ($lo){return codeHex2utf($m[1],$lo);}, $str);

 

そもそもこのエラーは何?

preg_replace()のe修飾子はPHP5.5.0から非推奨になり、エラーが表示されるらしい。

 

参考サイト

https://stackoverflow.com/questions/29432453/mpdf-error-preg-replace-the-e-modifier-is-deprecated-use-preg-replace-cal

 

まとめ

mPDFで「PHP Deprecated:  preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in」エラーが発生する場合はfunctions.phpを編集することで解決する。

 - PHP

  関連記事

PHPでソーシャル(SNS)ログインする方法

「facebook / twitter / Googleアカウントでログインする ...

PHPのカレンダー関数

カレンダー関数で使えるかもしれないものをメモ。 ■cal_days_in_mon ...

PHPで「Unable to allocate~」とエラー

PHPで「Unable to allocate memory for pool」 ...

Cannot re-assign auto-global variableのエラー

PHPバージョンアップに伴い「Fatal error: Cannot re-as ...

PHPで特定のファイル内のみタイムアウトを無効にする

重たい処理をするページだけ、タイムアウトを無効にする場合のメモ。 以下をPHPフ ...

PHPでis_fileとfile_existsについて

ファイルの存在チェックを行う際に、file_exists関数を 使用していたが、 ...

SendGridを使ってメールサーバを構築せずにPHPからメールを送信する方法

メールサーバを構築せずに独自ドメインのメールアドレスにてメール送信を行いたい。過 ...

PHPでxmlのpubDateを見やすい形に整形する

PHPでsimplexml_load_file関数とかを使ってデータを取得した際 ...

PHPで配列じゃないものに対してソート

PHP Warning:  sort() expects parameter 1 ...

curlでPOSTデータ送信

ここで使ったcurlだけど補足とか諸々。 ■curlでPOST 並列処理する際に ...