Home  >  Article  >  Backend Development  >  php步骤:N个字符间插入其它字符的方法

php步骤:N个字符间插入其它字符的方法

WBOY
WBOYOriginal
2016-06-13 13:14:18815browse

php方法:N个字符间插入其它字符的方法

最近做一个excel下载功能,为了解决每一列宽度,只能手动调整分行,于是写了一个自动换行的方法

function mbstringtoarray($str,$cut_len,$charset,$inter="<br>") {
  $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);
}

用起来还不错,呵呵,这个也解决了中文字符乱码的问题。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn