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

I use MPDF to generate pdf files in the encoder.

my controller function looks 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

  <?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 create a PDF file from a file of the form section1 . but when I call the controller function save_pdf , I got errors below

enter image description here

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

enter image description here

I studied mpdf documentation and worked correctly in simple php. but I want to create a pdf file in Codeigniter . How to solve such errors in mpdf ? I would appreciate any help where I can generate a pdf file using mpdf in Codeigniter . thanks.

+5
source share
3 answers

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

+16
source

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

using this 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.

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

All Articles