--- fenglin/lib/str_process.inc.php 2025/07/02 02:00:57 1.20 +++ fenglin/lib/str_process.inc.php 2025/10/30 11:19:14 1.22 @@ -10,14 +10,14 @@ function str_length(string $str) : int // Process UTF-8 Chinese characters $v1 = ord($c); - if ($v1 & 0b10000000) //head of multi-byte character + if ($v1 & 0x80) //head of multi-byte character { - $v2 = ($v1 & 0b01110000) << 1; - while ($v2 & 0b10000000) + $v2 = ($v1 & 0x70) << 1; + while ($v2 & 0x80) { $i++; $c .= $str[$i]; - $v2 = ($v2 & 0b01111111) << 1; + $v2 = ($v2 & 0x7f) << 1; } $ret += 2; @@ -31,11 +31,11 @@ function str_length(string $str) : int return $ret; } -function split_line(string $str, string $prefix = "", int $width = 76, int $lines_limit = PHP_INT_MAX, string $end_of_line = "\n") : string +function split_line(string $str, string $prefix = "", int $width = PHP_INT_MAX, int $lines_limit = PHP_INT_MAX, string $end_of_line = "\n") : string { if ($width <= 0) { - return $str; + $width = PHP_INT_MAX; } $result = ""; @@ -72,14 +72,14 @@ function split_line(string $str, string // Process UTF-8 Chinese characters $v1 = ord($c); - if ($v1 & 0b10000000) //head of multi-byte character + if ($v1 & 0x80) //head of multi-byte character { - $v2 = ($v1 & 0b01110000) << 1; - while ($v2 & 0b10000000) + $v2 = ($v1 & 0x70) << 1; + while ($v2 & 0x80) { $i++; $c .= $str[$i]; - $v2 = ($v2 & 0b01111111) << 1; + $v2 = ($v2 & 0x7f) << 1; } // Each UTF-8 CJK character should use two character length for display