mpdf error - preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead

preg_replace php 7
mpdf in laravel
mpdf composer

i'm using MPDF to generate pdf files in codeigniter.

my controller function look like

   function save_pdf($std_id)
   {
     $data['section1_report']= $this->common_model->get_details('tbl_section1',array('id'=>$std_id));
     $html = $this->load->view('reports/section1',$data,true);
      // print_r($html);exit; 
     $this->load->library('pdf');
     $pdf = $this->pdf->load();
     $pdf->WriteHTML($html);
     $pdf->Output();
}

my pdf library is

 <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
   class pdf {    
      function pdf()
      {
         $CI = & get_instance();
         log_message('Debug', 'mPDF class is loaded.');
      }

     function load($param=NULL)
     {
         include_once APPPATH.'/mpdf/mpdf.php';         
         if ($params == NULL)
         {
             $param = '"en-GB-x","A4","","",10,10,10,10,6,3';         
         }         
       return new mPDF($param);
     }
  }

i want to generate pdf file from the view file section1. but when i call the controller function save_pdf , i got the errors as below

when i print_r($html);exit; , it displays all the contents from the view file.i used preg_replace_callback instead of preg_replace in mpdf/includes/functions.php but it's still showing error like this

i studied the mpdf documentation and it's working correctly in plain php. but i want to generate pdf file in Codeigniter. how to solve such errors in mpdf? I would appreciate any help where i can generate pdf file using mpdf in Codeigniter. thank you.


Try replacing lines 79 and 80 of functions.php with this:

$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);

Source: https://github.com/carlholmberg/mpdf/issues/1

preg_replace(): The /e modifier is deprecated, use , mpdf error - preg_replace(): The /e modifier is deprecated, use all the contents from the view file.i used preg_replace_callback instead of preg_replace in  preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead. This happens with php5.5 #1 onkar-infoobjects opened this issue Jul 19, 2013 · 8 comments


$str = preg_replace('/\&\#([0-9]+)\;/me', "code2utf('\\1',{$lo})",$str);
$str = preg_replace('/\&\#x([0-9a-fA-F]+)\;/me', "codeHex2utf('\\1',{$lo})",$str);
// Remove above and add below code in includes/functions.php
$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);

// Also comment below line in mpdf.php
$html = preg_replace('/\{DATE\s+(.*?)\}/e',"date('\\1')",$html );

Deprecated: preg_replace() · Issue #61 · mpdf/mpdf · GitHub, preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead. line 79 & 80 but now in php5.5 it have been deprecated with preg_replace_callback(), what would be solution of this problem. cat -n MPDF57/mpdf.php | sed -n '7663p; 12058p' 7663 $html = preg_replace('/\{DATE\​s+(. Despite being a well-documented issue in PHP manual (deprecated since v5.5 and then unsupported since v7.0.0), the above warning is easily one of the most annoying backward-incompatible changes a developer could face when performing the upgrade: adopting the suggested fix – reimplement the code using the newer and more robust preg_replace_callback function – is not always easy, because the


$str = preg_replace('/\&\#([0-9]+)\;/me', "code2utf('\\1',{$lo})",$str);
$str = preg_replace('/\&\#x([0-9a-fA-F]+)\;/me', "codeHex2utf('\\1',{$lo})",$str);
// Remove above and add below code in includes/functions.php
$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);

// Also comment below line in mpdf.php
$html = preg_replace('/\{DATE\s+(.*?)\}/e',"date('\\1')",$html );

PHP, Hi there, i use 5.7.4 version of mpdf and my php version is 5.6.12. I use The /e modifier is deprecated, use preg_replace_callback instead in Casimir is correct it is the e modifier that is being depricated.preg_replace_callback is pretty cool, though. Basically, you just make a function that gets fed the matches and use that for doing the evaluation.


I replaced these lines:

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

with these line:

   $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);

and it worked correctly.

Deprecated function: preg_replace(): The /e modifier is deprecated , PHP – How to fix the “Warning: preg_replace(): The /e modifier is no longer supported” error in PHP7 Despite being a well-documented issue in PHP manual (deprecated since v5.5 and then unsupported since Use preg_replace_callback instead of preg_replace. Print Friendly & PDF Download. Labels: Deprecated: preg_replace(): The /e modifier is deprecated, MPDF error, use preg_replace_callback instead in MPDF57\includes\functions.php 1 comment: Unknown 26 April 2017 at 22:23


‍ Mpdf error, Deprecated function: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in Project: Printer, email and PDF versions. Version: 7.x-2.0. Component: Code. Priority: Normal. Category: Bug report. Re: Deprecated: preg_replace(): The /e modifier is deprecated Post by mbabker » Sun Oct 09, 2016 4:16 pm Upgrade to at least 2.5.15 to address that deprecation warning, preferably upgrade to 2.5.28, and ensure you have all out-of-cycle security patches applied.


Galaxy Code: MPDF error Deprecated: preg_replace(): The /e , Try replacing lines 79 and 80 with functions.php as follows: $str = preg_replace_callback('/\&\#([0-9]+)\;/m', function($m) use ($lo){return code2utf($​m[1],$lo); }  Deprecated function: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead


codeigniter mpdf error preg_replace(): The e modifier is deprecated , Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in MPDF57\includes\functions.php on line 99. So How can you solve this problem? follow below steps: In file "MPDF57/mpdf.php"  Deprecated features in PHP 5.5.x. ext/mysql deprecation. The original MySQL extension is now deprecated, and will generate E_DEPRECATED errors when connecting to a database. Instead, use the MySQLi or PDO_MySQL extensions. preg_replace() /e modifier. The