Home  >  Article  >  Backend Development  >  String interception function starts_PHP tutorial

String interception function starts_PHP tutorial

WBOY
WBOYOriginal
2016-07-20 10:59:38877browse

字符串截取函数开始        function csubStr($str,$start,$len)
        {
                $strlen=strlen($str);
                $clen=0;
                for($i=0;$i<$strlen;$i++,$clen++)
                {
                        if ($clen>=$start+$len)
                        break;

                        if(ord(substr($str,$i,1))>0xa0)
                        {
                                if ($clen>=$start)
                                $tmpstr.=substr($str,$i,2);
                                $i++;
                        }
                        else
                        {
                                if ($clen>=$start)
                                $tmpstr.=substr($str,$i,1);
                        }
        }
       
        return $tmpstr;
        }
       
    //------------------------------字符串截取函数结束-------------------------------------------

/*使用方法:
$str=csubStr("ipod光环太耀眼 苹果的电脑本业该怎么办?",0,20);
echo $str;
?>       


www.bkjia.comtruehttp://www.bkjia.com/PHPjc/445564.htmlTechArticle字符串截取函数开始 function csubStr($str,$start,$len) { $strlen=strlen($str); $clen=0; for($i=0;$i$strlen;$i++,$clen++) { if ($clen=$start+$len) break; if(ord(substr($str,...
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