Question

I'm using pbkdf2(), and I need to print its output to debug an error. it generates strange string like "�O� BIa���!J��".

Neither htmlentities() or htmlSpecialChars() are able to convert these chars to anything more readable.

I was thinking in converting them to UTF-8 entities, like 激, and see if browser will render them better this way. If not, I'd rather see their UTF-8 number than these chars.

I tried utf8_encode() and utf8_decode(), alone and combined with htmlentities() and htmlSpecialChars(). No luck at all.

any idea what could be done?

Was it helpful?

Solution

Try this function:

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);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top