Home >Backend Development >PHP Tutorial >PHP method: How to insert other characters between N characters_PHP tutorial
I recently made an excel download function. In order to solve the width of each column, I could only manually adjust the rows, so I wrote a method for automatic line wrapping
[php
function mbstringtoarray($str,$cut_len,$charset,$inter="
") {
$strlen=mb_strlen($str,$charset);
$array=array();
while($strlen){
$array[]=mb_substr($str,0,$cut_len,$charset);
$str=mb_substr($str,$cut_len,$strlen-$cut_len,$charset);
$strlen=mb_strlen($str,$charset);
}
return implode($inter,$array);
}
It’s pretty good to use, haha, this also solves the problem of garbled Chinese characters.