2012年3月4日 星期日

PHP 文字轉碼UNICODE


// 使用 iconv

$unicode_html = '&#' .base_convert(bin2hex(iconv('UTF-8', 'UCS-4', $str)), 16, 10)';'; 



// 使用 mb_convert_encoding

$unicode_html = '&#' .base_convert(bin2hex(mb_convert_encoding($str, 'ucs-4', 'utf-8')), 16, 10)';';




//回轉
$str = mb_convert_encoding($unicode_html, 'UTF-8', 'HTML-ENTITIES');