--- fenglin/lib/str_process.inc.php 2005/03/23 17:31:14 1.7 +++ fenglin/lib/str_process.inc.php 2025/03/01 09:02:28 1.9 @@ -1,48 +1,37 @@ 127) - { - $hz_ok = (!$hz_ok); - } - if (ord($str[$i])<=127) - { - $hz_ok = true; - } - if ($line_count >= $width && $hz_ok) + $c = mb_substr($str,$i,1,'UTF-8'); + $line.=$c; + + // Each UTF-8 CJK character should use two character length for display + $line_len += (strlen($c) <= 2 ? 1 : 2); + + if ($line_len >= $width) { - $lines[$lines_count++] = $line; + $result .= ($line . "\n"); $line = $prefix; - $line_count = strlen($line); + $line_len = $prefix_len; } } - $lines[$lines_count++] = $line; + $result .= ($line . "\n"); - $result = ""; - for($i=0;$i<$lines_count;$i++) - { - $result.=($lines[$i]."\r\n"); - } return $result; } -function str_process($str,$prefix="",$width=75) +function str_process($str,$prefix="",$width=76) { $result = ""; @@ -63,8 +52,8 @@ function str_b_lines($str,$max_line=1) $lines = explode("\n",str_replace("\r\n","\n",$str)); foreach($lines as $tmp => $line) { - $result .= ($line."\r\n"); - $l += (strlen($line)/256 + 1); + $result .= ($line."\n"); + $l += (mb_strlen($line,'UTF-8')/128 + 1); if ($l >= $max_line) break; }