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); }
参考文章:http://randomchaos.com/documents/?source=php_and_unicode
程序采用ASP+ACCESS开发完成。中英繁三语言,所有页面采用UTF-8全球通用编码,兼容简体中文、繁体中文及英语,适用于中小企业网站运用。后台数据同时录入中文及英文,繁体采用JS自动转换,无需维护。免费版主要功能如下:·系统管理:系统综合设置、管理员管理、数据库备份、上传文件管理。·单页管理:自由无限制添加个性页面,如:公司简介、组织结构、联系我们等
以上就介绍了php中utf-8转unicode,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。










