--- fenglin/lib/str_process.inc.php 2004/06/25 08:26:49 1.2 +++ fenglin/lib/str_process.inc.php 2025/03/01 09:02:28 1.9 @@ -1,55 +1,64 @@ = $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; - $line = $pre; - $line_count = strlen($line); + $result .= ($line . "\n"); + $line = $prefix; + $line_len = $prefix_len; } - $line.=$str[$i]; - $line_count++; - if (ord($str[$i])>127) - $hz_ok = (!$hz_ok); - if (ord($str[$i])<=127) - $hz_ok = true; } - $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,$pre="",$width=75) +function str_process($str,$prefix="",$width=76) { $result = ""; $lines = explode("\n",str_replace("\r\n","\n",$str)); - foreach($lines as $line) + foreach($lines as $tmp => $line) { - $result .= split_line($line,$pre,$width); + $result .= split_line($line,$prefix,$width); } return $result; } +function str_b_lines($str,$max_line=1) +{ + $result = ""; + $l = 0; + $lines = explode("\n",str_replace("\r\n","\n",$str)); + foreach($lines as $tmp => $line) + { + $result .= ($line."\n"); + $l += (mb_strlen($line,'UTF-8')/128 + 1); + if ($l >= $max_line) + break; + } + + return $result; +} + ?>