PHP版 漢字轉(zhuǎn)碼的實現(xiàn)詳解
更新時間:2013年06月09日 15:51:06 作者:
本篇文章是對用php實現(xiàn)漢字轉(zhuǎn)碼進行了詳細的分析介紹,需要的朋友參考下
如下所示:
<?php
function unicode_encode($str, $encoding='GBK', $prefix='&#', $postfix=';'){
$str = iconv($encoding, 'UCS-2', $str);
$arrstr = str_split($str, 2);
$unistr = '';
for($i=0, $len=count($arrstr); $i<$len; $i++)
{
$dec = hexdec(bin2hex($arrstr[$i]));
$unistr .= $prefix.$dec.$postfix;
}
return $unistr;
}
$str = '<b>哈哈</b>';
$unistr = unicode_encode($str);
echo $unistr.'<br />';
?>
復(fù)制代碼 代碼如下:
<?php
function unicode_encode($str, $encoding='GBK', $prefix='&#', $postfix=';'){
$str = iconv($encoding, 'UCS-2', $str);
$arrstr = str_split($str, 2);
$unistr = '';
for($i=0, $len=count($arrstr); $i<$len; $i++)
{
$dec = hexdec(bin2hex($arrstr[$i]));
$unistr .= $prefix.$dec.$postfix;
}
return $unistr;
}
$str = '<b>哈哈</b>';
$unistr = unicode_encode($str);
echo $unistr.'<br />';
?>
相關(guān)文章
PHP讀取網(wǎng)頁文件內(nèi)容的實現(xiàn)代碼(fopen,curl等)
php小偷程序中經(jīng)常需要獲取遠程網(wǎng)頁的內(nèi)容,下面是一些實現(xiàn)代碼,需要的朋友可以慘況下。2011-06-06
Windows平臺實現(xiàn)PHP連接SQL Server2008的方法
這篇文章主要介紹了Windows平臺實現(xiàn)PHP連接SQL Server2008的方法,結(jié)合實例形式分析了Windows平臺PHP連接SQL Server2008所需的相關(guān)dll動態(tài)鏈接庫文件及相應(yīng)的配置與使用方法,需要的朋友可以參考下2017-07-07
PHP is_subclass_of函數(shù)的一個BUG和解決方法
這篇文章主要介紹了PHP is_subclass_of函數(shù)的一個BUG和解決方法,這個BUG存在于php5.3.7版本以前,并且針對interface方面,需要的朋友可以參考下2014-06-06
實現(xiàn)在同一方法中獲取當前方法中新賦值的session值解決方法
這篇文章主要介紹了在同一方法中獲取當前方法中新賦值的session值解決方法,需要的朋友可以參考下2014-06-06

