--- fenglin/lib/str_process.inc.php 2025/03/24 05:46:49 1.11 +++ fenglin/lib/str_process.inc.php 2025/10/31 10:31:55 1.24 @@ -1,12 +1,74 @@ -= $lines_limit) + { + break; + } + + $result .= ($line . $end_of_line); $lines_count++; $line = $prefix; $line_len = $prefix_len; @@ -33,21 +100,25 @@ 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 if ($line_len + 2 > $width) { - $result .= ($line . "\n"); + if ($lines_count + 1 >= $lines_limit) + { + break; + } + + $result .= ($line . $end_of_line); $lines_count++; $line = $prefix; $line_len = $prefix_len; @@ -59,15 +130,20 @@ function split_line($str, $prefix = "", $line_len++; } - $line .= $c; - - if ($line_len >= $width) + if ($line_len > $width) { - $result .= ($line . "\n"); + if ($lines_count + 1 >= $lines_limit) + { + break; + } + + $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) @@ -77,4 +153,3 @@ function split_line($str, $prefix = "", return $result; } -?>