Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 461
Sujan Shrestha Avatar asked Apr 03 '15 12:04

Sujan Shrestha


2 Answers

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

like image 84
GluePear Avatar answered Oct 08 '22 14:10

GluePear


$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 );
like image 3
ImBhavin95 Avatar answered Oct 08 '22 14:10

ImBhavin95