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