超碰免费人人操|国产视频二区久久艹人人操|欧美激情第一页在线|久热最新无码中文视频|91精品国际成人|亚洲成人精品在线视频青青草|久草免费高清完整在线观看|你懂的AV在线日本黄网页|国产黄色AV日韩女同网|欧美成人色区导航片av

php實(shí)現(xiàn)utf-8轉(zhuǎn)unicode函數(shù)分享

時(shí)間:2025-11-18 09:45:00 php語(yǔ)言

php實(shí)現(xiàn)utf-8轉(zhuǎn)unicode函數(shù)分享

  php實(shí)現(xiàn)utf-8轉(zhuǎn)unicode函數(shù)如何操作呢?需要的朋友可以參考下,代碼很簡(jiǎn)單,功能卻很實(shí)用,推薦給大家。希望對(duì)大家有所幫助!

  奉上代碼先:

  復(fù)制代碼 代碼如下:

  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') ) {

  /pic/p>

  if ($thisValue >= ord('0') && $thisValue <= ord('9')) {

  /pic/p>

  $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;

  } /pic/p>

  } /pic/p>

  }

  } /pic/p>

  return implode("",$unicode);

  }

【php實(shí)現(xiàn)utf-8轉(zhuǎn)unicode函數(shù)分享】相關(guān)文章:

PHP如何實(shí)現(xiàn)Unicode和Utf-8編碼相互轉(zhuǎn)換07-31

php字符轉(zhuǎn)URL地址的函數(shù)02-14

php制作unicode解碼工具10-13

分享php過(guò)濾XSS攻擊的函數(shù)11-02

php實(shí)現(xiàn)求相對(duì)時(shí)間函數(shù)02-21

PHP與UTF-8的最佳實(shí)踐02-07

淺析PHP中的UNICODE編碼與解碼12-23

php使用ftp函數(shù)實(shí)現(xiàn)簡(jiǎn)單上傳功能02-07

php自定義函數(shù)實(shí)現(xiàn)漢字分割替換01-06