<?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;
} // www.jb200.com
$str = '<b>哈哈</b>';
$unistr = unicode_encode($str);
echo $unistr.'<br />';
?>