Reputation: 758
I have a CURL script that extract the data from a normal JSON feed. The feed return html code but the special html characters are wrongly formated.
For example, I get the following string:
★ Beautiful new graphics ★ Gorgeous new organic environments ★ New obstacles
The data is stored into a DB and I want to store the special html characters as well.
How can I preserve the special html characters. My script is as follow:
$curl_session = curl_init();
curl_setopt($curl_session, CURLOPT_URL,'https://itunes.apple.com/lookup?id=572395608');
curl_setopt($curl_session, CURLOPT_CONNECTTIMEOUT,10);
curl_setopt($curl_session, CURLOPT_TIMEOUT, 10);
curl_setopt($curl_session, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_session, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl_session, CURLOPT_SSL_VERIFYPEER, 0);
$source = curl_exec($curl_session);
$source_decoded = json_decode($source, true);
print_r($source_decoded);
exit;
Upvotes: 0
Views: 260
Reputation: 70863
You are receiving the characters as UTF-8, because this is the only encoding allowed and possible in JSON.
But you output them NOT as UTF-8. Change this. Send a content type header that tells the client which encoding has been used. Or convert the characters to an encoding you are using, and risk loosing those characters that cannot be encoded with it.
Upvotes: 1