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

Sujan Shrestha picture Sujan Shrestha · Apr 3, 2015 · Viewed 12k times · Source

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

enter image description here

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

enter image description here

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.

Answer

GluePear picture GluePear · Apr 3, 2015

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