--- fenglin/lib/str_process.inc.php 2025/03/28 10:31:26 1.13 +++ fenglin/lib/str_process.inc.php 2025/10/30 11:19:14 1.22 @@ -1,5 +1,5 @@ -= $lines_limit) @@ -71,15 +72,14 @@ function split_line($str, $prefix = "", // Process UTF-8 Chinese characters $v1 = ord($c); - if (($v1 & 0b10000000) == 0b10000000) //head of multi-byte character + if ($v1 & 0x80) //head of multi-byte character { - $v2 = ($v1 & 0b01111000) << 1; - while ($v2 & 0b10000000) + $v2 = ($v1 & 0x70) << 1; + while ($v2 & 0x80) { $i++; - $v3 = $str[$i]; - $c .= $v3; - $v2 = ($v2 & 0b01111111 ) << 1; + $c .= $str[$i]; + $v2 = ($v2 & 0x7f) << 1; } // Each UTF-8 CJK character should use two character length for display @@ -102,9 +102,7 @@ function split_line($str, $prefix = "", $line_len++; } - $line .= $c; - - if ($line_len >= $width) + if ($line_len > $width) { if ($lines_count + 1 >= $lines_limit) { @@ -114,8 +112,10 @@ function split_line($str, $prefix = "", $result .= ($line . $end_of_line); $lines_count++; $line = $prefix; - $line_len = $prefix_len; + $line_len = $prefix_len + 1; } + + $line .= $c; } if ($lines_count < $lines_limit) @@ -125,4 +125,3 @@ function split_line($str, $prefix = "", return $result; } -?>