Thursday, May 5, 2011

Input is not proper UTF-8, indicate encoding !

I faced with the error while exporting huge xml.

My solution for this was changing the code:
foreach($adData as $itemData )
{
$xmlData .= "<item><![CDATA[".$itemData."]]></item>";
}


Into this:
foreach($adData as $itemData )
{
$table = array('&' => '&amp;', '<' => '&lt;', '>' => '&gt;', '"' => '&quot;');
$data = str_replace(array_keys($table), array_values($table), $itemData);
$date = str_replace(" ","",$data); //there is one strange square symbol. after converting into chars //for blogspot it was removed :(
$data = htmlspecialchars(html_entity_decode($data, ENT_QUOTES, 'UTF-8'), ENT_NOQUOTES, 'UTF-8');
$xmlData .= "<item><![CDATA[".$itemData."]]></item>";
}

Hope it will help you solving your problem.
Anyways. Good luck!

No comments:

Post a Comment