dsfdsfds521521 2015-11-20 07:25
浏览 46

阅读评论字符Instagram时出错

I'm using php to read from INSTAGRAM API, get comment on its media

Eg.

sending $url = 'https://api.instagram.com/v1/media/'.$mediaID.'/comments?client_id='. clientID;

I read the results like this:

$instagramInfo = connectToInstagram($test);
$results = json_decode($instagramInfo, true);
foreach($results['data'] as $item){
$commentText = $item['text'];
echo $commentText.'<br/>';
}

Here's an example of the output:

™آƒأ™آٹأ™آ„ أ™آپأ™آٹأ™آƒ أکآ§أکآ° أ™آ†أ™آٹأکآھأ™آƒ أ™آˆأکآµأکآ®أ™آ‡ أکآ§أ™آ„أ™آ„أ™آ‡ أ™آ„أکآ§ أ™آٹأ™آˆأ™آپأ™آ‚أ™آƒ أ™آˆأ™آ„أکآ§ أ™آٹأکآ³أکآ¹أکآ¯أ™آƒ أکآ­أکآ³أکآ¨أ™آٹ أکآ§أ™آ„أ™آ„أ™آ‡ أ™آˆأ™آ†أکآ¹أ™آ… أکآ§أ™آ„أ™آˆأ™آƒأ™آٹأ™آ„ أکآ§أکآ° أکآ£أ™آ†أکآھ أکآھأ™آپأ™آƒأکآ± أ™آپأ™آٹأ™آ†أ™آٹ أکآ¨أکآ°أکآ§ أکآ§أ™آ„أکآ·أکآ±أ™آٹأ™آ‚أ™آ‡ أکآ±أ™آˆأکآ­ أکآ§أ™آ„أ™آ„أ™آ‡ أ™آ„أکآ§ أ™آٹأکآ³أکآ¹أکآ¯أ™آƒ أ™آ„أکآ§ أکآ¯أ™آ†أ™آٹأکآ§ أ™آˆأ™آ„أکآ§ أکآ¢أکآ®أکآ±

The issue I'm having is the comments are unknown chars. I tried to change the encode to UTF-8 it didn't work

any ideas?

  • 写回答

1条回答 默认 最新

  • doucigua0449 2015-11-20 08:12
    关注

    Try this one, this should escape all special characters, and probably wouldn't cause any problems anymore

    $instagramInfo = connectToInstagram($test);
    $results = json_decode($instagramInfo, true);
    foreach($results['data'] as $item){
        $commentText = htmlspecialchars($item['text']);
        echo $commentText.'<br/>';
    }
    
    评论

报告相同问题?