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

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

WBOY
Release: 2016-06-13 13:14:18
Original
855 people have browsed it

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);
}
Copy after login

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template