| 8 |
{ |
{ |
| 9 |
$c = $str[$i]; |
$c = $str[$i]; |
| 10 |
|
|
| 11 |
// Process GBK Chinese characters |
// Process UTF-8 Chinese characters |
| 12 |
$v1 = ord($c); |
$v1 = ord($c); |
| 13 |
if ($v1 > 127 && $v1 <= 255) // GBK chinese character |
if ($v1 & 0b10000000) //head of multi-byte character |
| 14 |
{ |
{ |
| 15 |
$i++; |
$v2 = ($v1 & 0b01110000) << 1; |
| 16 |
$c .= $str[$i]; |
while ($v2 & 0b10000000) |
| 17 |
|
{ |
| 18 |
|
$i++; |
| 19 |
|
$c .= $str[$i]; |
| 20 |
|
$v2 = ($v2 & 0b01111111) << 1; |
| 21 |
|
} |
| 22 |
|
|
| 23 |
$ret += 2; |
$ret += 2; |
| 24 |
} |
} |
| 70 |
continue; |
continue; |
| 71 |
} |
} |
| 72 |
|
|
| 73 |
// Process GBK Chinese characters |
// Process UTF-8 Chinese characters |
| 74 |
$v1 = ord($c); |
$v1 = ord($c); |
| 75 |
if ($v1 > 127 && $v1 <= 255) // GBK chinese character |
if ($v1 & 0b10000000) //head of multi-byte character |
| 76 |
{ |
{ |
| 77 |
$i++; |
$v2 = ($v1 & 0b01110000) << 1; |
| 78 |
$c .= $str[$i]; |
while ($v2 & 0b10000000) |
| 79 |
|
{ |
| 80 |
|
$i++; |
| 81 |
|
$c .= $str[$i]; |
| 82 |
|
$v2 = ($v2 & 0b01111111) << 1; |
| 83 |
|
} |
| 84 |
|
|
| 85 |
// Each GBK CJK character should use two character length for display |
// Each UTF-8 CJK character should use two character length for display |
| 86 |
if ($line_len + 2 > $width) |
if ($line_len + 2 > $width) |
| 87 |
{ |
{ |
| 88 |
if ($lines_count + 1 >= $lines_limit) |
if ($lines_count + 1 >= $lines_limit) |