Home >Backend Development >PHP Tutorial >PHP version Detailed explanation of the implementation of Chinese character transcoding_PHP tutorial

PHP version Detailed explanation of the implementation of Chinese character transcoding_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:07:40783browse

As shown below:

Copy code The code is as follows:

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 = 'Haha';
$unistr = unicode_encode($str);
echo $unistr.'
';
?> ;

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/327521.htmlTechArticle is as follows: Copy the code as follows: ?php function unicode_encode($str, $encoding='GBK', $prefix=''){ $str = iconv($encoding, 'UCS-2', $str); $arrstr = str_split($str, 2); $un...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn