《PHP應(yīng)用:php實(shí)現(xiàn)utf-8轉(zhuǎn)unicode函數(shù)分享》要點(diǎn):
本文介紹了PHP應(yīng)用:php實(shí)現(xiàn)utf-8轉(zhuǎn)unicode函數(shù)分享,希望對您有用。如果有疑問,可以聯(lián)系我們。
代碼很簡單,功能卻很實(shí)用,保舉給大家.PHP應(yīng)用
送上代碼先:PHP應(yīng)用
代碼如下:
public function utf8_unicode($str) {
??? $unicode = array();
??? $values = array();
??? $lookingFor = 1;
??? for ($i = 0; $i < strlen( $str ); $i++ ) {
??????? $thisValue = ord( $str[ $i ] );
??????? if ( $thisValue < ord('A') ) {
??????????? // exclude 0-9
??????????? if ($thisValue >= ord('0') && $thisValue <= ord('9')) {
???????????????? // number
???????????????? $unicode[] = chr($thisValue);
??????????? }
??????????? else {
???????????????? $unicode[] = '%'.dechex($thisValue);
??????????? }
??????? } else {
??????????? if ( $thisValue < 128) {
??????????????? $unicode[] = $str[ $i ];
??????????? } else {
??????????????? if ( count( $values ) == 0 ) {
??????????????????? $lookingFor = ( $thisValue < 224 ) 必修 2 : 3;
??????????????? }
??????????????? $values[] = $thisValue;
??????????????? if ( count( $values ) == $lookingFor ) {
??????????????????? $number = ( $lookingFor == 3 ) 必修
??????????????????????? ( ( $values[0] % 16 ) * 4096 ) + ( ( $values[1] % 64 ) * 64 ) + ( $values[2] % 64 ):
??????????????????????? ( ( $values[0] % 32 ) * 64 ) + ( $values[1] % 64 );
??????????????????? $number = dechex($number);
??????????????????? $unicode[] = (strlen($number)==3)必修"\u0".$number:"\u".$number;
??????????????????? $values = array();
??????????????????? $lookingFor = 1;
??????????????? } // if
??????????? } // if
??????? }
??? } // for
??? return implode("",$unicode);
}
《PHP應(yīng)用:php實(shí)現(xiàn)utf-8轉(zhuǎn)unicode函數(shù)分享》是否對您有啟發(fā),歡迎查看更多與《PHP應(yīng)用:php實(shí)現(xiàn)utf-8轉(zhuǎn)unicode函數(shù)分享》相關(guān)教程,學(xué)精學(xué)透。維易PHP學(xué)院為您提供精彩教程。
轉(zhuǎn)載請注明本頁網(wǎng)址:
http://www.fzlkiss.com/jiaocheng/12818.html