Skip to content
Advertisement

How to convert String with “ (ISO-8859-1) characters to normal (UTF-8)characters?

<li>Jain R.K. and Iyengar S.R.K., “Advanced Engineering Mathematicsâ€, Narosa Publications,</li>

i have lot a raw html string in database. all the text have these weird characters. how can i convert to normal text for saving back it back in database.

$final = '<li>Jain R.K. and Iyengar S.R.K., “Advanced Engineering Mathematicsâ€, Narosa Publications,</li>';
$final = utf8_encode($final);

$final = htmlspecialchars_decode($final);

$final = html_entity_decode($final, ENT_QUOTES, "UTF-8");

$final = utf8_decode($final);

echo $final;

i tried above code, it displays correctly in web browser but still saving the same weird characters in database.

the charset of database is utf-8

Advertisement

Answer

$final = '<li>Jain R.K. and Iyengar S.R.K., “Advanced Engineering Mathematicsâ€, Narosa Publications,</li>';

$final = str_replace("Â", "", $final);
$final = str_replace("’", "'", $final);
$final = str_replace("“", '"', $final);
$final = str_replace('–', '-', $final);
$final = str_replace('â€', '"', $final);

for past datas, i replaced the weird characters with UTF-8 characters.

for future datas, i made the charset to utf8 in php, html and databases connections.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement