2013-04-05 32 views
1

我使用PBKDF2(),并且我需要打印其输出到调试错误。它会产生奇怪的字符串,如“ O BIa !J ”。转换古怪字符为UTF-8码参考

无论ヶ辆()或用htmlspecialchars()能够将这些字符转换成任何东西更易读。

我想在将它们转换为UTF-8的实体,如激,看看浏览器将使其更好的这种方式。如果没有,我宁愿看到他们的UTF-8数字比这些字符。

我试图函数utf8_encode()和utf8_decode(),单独的以及与ヶ辆()和用htmlspecialchars()相结合。没有运气。

任何想法什么可以做?

+0

哪里你得到从orignial字符串,什么是原有的代表性? – Esailija 2013-04-06 09:30:04

回答

2

试试这个功能:

function convert_smart_quotes($string) 
{ 
$string = htmlentities($string); 
$string = mb_convert_encoding($string, 'HTML-ENTITIES', 'utf-8'); 
$string = htmlspecialchars_decode(utf8_decode(htmlentities($string, ENT_COMPAT, 'utf-8', false))); 

$s = array(
    chr(145) => "'", 
    chr(146) => "'", 
    chr(147) => '"', 
    chr(148) => '"', 
    chr(151) => '-', 
    's©' => '©', 
    '®' => '®', 
    '™' => '™', //™ 
    '“' => '"', // left side double smart quote 
    'â€' => '"', // right side double smart quote 
    '‘' => "'", // left side single smart quote 
    '’' => "'", // right side single smart quote 
    '…' => '...', // elipsis 
    '—' => '-', // em dash 
    '–' => '-', // en dash 
); 

return strtr($string, $s); 
}