tcpdf导出preg_split()报错linux Compilation failed: this version of PCRE is compiled without UTF

1.pcre编译异常导致preg_split()不能匹配UTF8编码中文字符串
解决方法:
修改\tcpdf\include\tcpdf_static.php文件中的pregSplit函数
源码:

		public static function pregSplit($pattern, $modifiers, $subject, $limit=NULL, $flags=NULL) {
	// the bug only happens on PHP 5.2 when using the u modifier
	if ((strpos($modifiers, 'u') === FALSE) OR (count(preg_split('//u', "\n\t", -1, PREG_SPLIT_NO_EMPTY)) == 2)) {
		return preg_split($pattern.$modifiers, $subject, $limit, $flags);
	}
	// preg_split is bugged - try alternative solution
	$ret = array();
	while (($nl = strpos($subject, "\n")) !== FALSE) {
		$ret = array_merge($ret, preg_split($pattern.$modifiers, substr($subject, 0, $nl), $limit, $flags));
		$ret[] = "\n";
		$subject = substr($subject, ($nl + 1));
	}
	if (strlen($subject) > 0) {
		$ret = array_merge($ret, preg_split($pattern.$modifiers, $subject, $limit, $flags));
	}
	return $ret;
}

改为:

public static function pregSplit($pattern, $modifiers, $subject, $limit=NULL, $flags=NULL) {
	// the bug only happens on PHP 5.2 when using the u modifier
	if ((strpos($modifiers, 'u') === FALSE) OR (count(preg_split('//', "\n\t", -1, PREG_SPLIT_NO_EMPTY)) == 2)) {
        $length = mb_strlen($subject, 'utf-8');
        $titlearray = [];
        for ($i=0; $i<$length; $i++)
        {
            $titlearray[] = mb_substr($subject, $i, 1, 'utf-8');
        }
		return $titlearray;
	}
	// preg_split is bugged - try alternative solution
	$ret = array();
	while (($nl = strpos($subject, "\n")) !== FALSE) {
        $length = mb_strlen($subject, 'utf-8');
        $titlearray = [];
        for ($i=0; $i<$length; $i++)
        {
            $titlearray[] = mb_substr($subject, $i, 1, 'utf-8');
        }
		$ret = array_merge($ret, $titlearray);
		$ret[] = "\n";
		$subject = substr($subject, ($nl + 1));
	}
	if (strlen($subject) > 0) {
        $length = mb_strlen($subject, 'utf-8');
        $titlearray = [];
        for ($i=0; $i<$length; $i++)
        {
            $titlearray[] = mb_substr($subject, $i, 1, 'utf-8');
        }
		$ret = array_merge($ret, $titlearray);
	}
	return $ret;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值