新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
PHPSubstr庫函數(shù)的功能介紹
初學(xué)PHP語言的朋友對(duì)于時(shí)常碰到的陌生函數(shù)都比較有興趣,一旦發(fā)現(xiàn)了這個(gè)函數(shù)的特殊功能后,往往都會(huì)很興奮。我們今天要給大家介紹的是關(guān)于PHP Substr庫函數(shù)的具體功能介紹。

讓客戶滿意是我們工作的目標(biāo),不斷超越客戶的期望值來自于我們對(duì)這個(gè)行業(yè)的熱愛。我們立志把好的技術(shù)通過有效、簡單的方式提供給客戶,將通過不懈努力成為客戶在信息化領(lǐng)域值得信任、有價(jià)值的長期合作伙伴,公司提供的服務(wù)項(xiàng)目有:申請域名、雅安服務(wù)器托管、營銷軟件、網(wǎng)站建設(shè)、溪湖網(wǎng)站維護(hù)、網(wǎng)站推廣。
#t#下面這個(gè)PHP Substr庫函數(shù)程序不算完美,但處理一般的中文(GB18030,GB2312,BIG5)是沒有問題的。這個(gè)函數(shù)不適合utf-8編碼的文字。
- //$str字符串
- //$max 最大字符數(shù)
- function Substring($str,$max){
- $cnt=0; //實(shí)際計(jì)數(shù)
- $index=0; //當(dāng)前索引
- $output=''; //輸出
- //
- while($cnt<$max && $index
- $output.=$str[$index];
- //big5
- if(ord($str[$index])>=0x81 &&
ord($str[$index])<=0xfe){- if($index+1
- if( (ord($str[$index+1])>=0x40
&& ord($str[$index+1])<0x7e)- || (ord($str[$index+1])>=0xa1
&& ord($str[$index+1])<=0xfe) ){- $index++;
- $output.=$str[$index];
- }
- }
- }
- //gb2312
- else if(ord($str[$index])>=0xa1
&& ord($str[$index])<=0xf7){- $output.=$str[$index];
- if($index+1
- if(ord($str[$index+1])>=0xa1
&& ord($str[$index+1])<0xfe){- $index++;
- $output.=$str[$index];
- }
- }
- }
- else{
- }
- $cnt++;
- $index++;
- }
- return $output;
- }
以上代碼示例就是PHP Substr庫函數(shù)在截取中文字符時(shí)的具體使用方法。
分享文章:PHPSubstr庫函數(shù)的功能介紹
文章源于:http://m.fisionsoft.com.cn/article/cdgedii.html


咨詢
建站咨詢
