<?php header('Content-Type:text/html;charset=utf-8'); function cutstr($str,$len){ if($len<0){return null;} $chars = 0; //字符數(shù)量 $offset = 0; $res = ''; while($chars < $len){ $high = decbin(ord(substr($str,$offset,1))); if(strlen($high) < 8){ $count = 1; }else if(substr($high,0,3) == '110'){ $count = 2; }else if(substr($high,0,4)== '1110'){ $count = 3; } echo $count.'<br/>'; $res .= substr($str,$offset,$count); $chars += 1; $offset += $count; } return $res; } $str = '你好aaaaa'; echo cutstr($str,2); ?>
文章標(biāo)題:php中文截取無亂碼
當(dāng)前鏈接:http://aaarwkj.com/article38/gghcpp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供面包屑導(dǎo)航、建站公司、自適應(yīng)網(wǎng)站、App設(shè)計、網(wǎng)站收錄、電子商務(wù)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)