Home > Article > Backend Development > Use PHP's built-in multi-byte processing function to process Chinese, the best way_PHP tutorial
echo "
____________________
";
$string="242432 The sense of opposition is 456, and the fault is widespread in the embassy area 7890abc";
$mb_strlen=mb_strlen($string);
$len=20;
echo $string."
";
echo "The total length is: ".($mb_strlen+1)."
";
echo "Number of interceptions: ".$len."
";
for($i=1;$i<=$mb_strlen+1;$i++){
if($i>$len){
echo $i." → ".mb_substr($string,$i)."…
";
continue;
}
echo $i." → ".mb_substr($string,$i)."
";
}
?>
See PHP’s Multi-Byte String Functions,
(1) Use --enable-mbstring=cn
when compiling
(2) Modify /usr/local/lib/php.inc
default_charset = "zh-cn"
mbstring.language = zh-cn
mbstring.internal_encoding =zh-cn
Everthing I do, I do it for you!
My linux!