Home  >  Article  >  Backend Development  >  php截取字符串,解决乱码问题与html标签问题

php截取字符串,解决乱码问题与html标签问题

WBOY
WBOYOriginal
2016-06-23 13:31:381073browse

public function  f截取字符串($str,$start,$len) {//$str是指字符串,$start指字符串的起始位置,$len指字符串长度    $len=$len*3;    $strlen=$start+$len; //用$strlen存储字符串的总长度    $tmpstr='';    for($i=0;$i0xa0) { //如果字符串中出现汉字,也就是ASC码大于0xa0的。作出判断与英文字符不一样。            $tmpstr.=mb_substr($str,$i,2,'utf-8');            //$tmpstr.=substr($str,$i,2);            $i++;        }        else            $tmpstr.=mb_substr($str,$i,1,'utf-8');    }    return $tmpstr;}

版权声明:本文为博主原创文章,未经博主允许不得转载。

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