<?php
function wordwrap_utf8( $string, $length=75, $break="\n", $cut=false) {
preg_match_all("/./u", $string, $matches);
$s = $matches[0];
$ct = count( $s );
for($i=0; $i<ceil($ct/$length) ; $i++) {
$ns .= implode("", array_slice($s, $i*$length, $length) ) . $break;
}
return $ns;
}
?>
function wordwrap_utf8( $string, $length=75, $break="\n", $cut=false) {
preg_match_all("/./u", $string, $matches);
$s = $matches[0];
$ct = count( $s );
for($i=0; $i<ceil($ct/$length) ; $i++) {
$ns .= implode("", array_slice($s, $i*$length, $length) ) . $break;
}
return $ns;
}
?>
解决了wordwrap截断汉字的问题。缺点是$cut参数无法使用,会将英文单词截断。
没有评论:
发表评论