Codeigniter mpdf错误-preg_replace():不推荐使用/e修饰符,请改用preg_replace_回调
我正在使用MPDF在codeigniter中生成pdf文件 我的控制器功能看起来像Codeigniter mpdf错误-preg_replace():不推荐使用/e修饰符,请改用preg_replace_回调,codeigniter,mpdf,Codeigniter,Mpdf,我正在使用MPDF在codeigniter中生成pdf文件 我的控制器功能看起来像 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,
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();
}
我的pdf
库是
<?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);
}
}
尝试将functions.php
的第79行和第80行替换为:
$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);
来源:我替换了这些行:
$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);
它工作正常。我刚在谷歌上搜索了“带Codeigniter的MPDF”,试试看,例如,这一款适合我。我使用了这个解决方案。它肯定会删除错误,但会使pdf损坏。但是当我评论你要求评论的那行时,它会为你的改变而欢呼!
$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 );
$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 );