Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

file_get_contents is returning back a corrupted characters from facbook feed.

Avatar of Ashraf Hassanein
Ashraf Hassanein asked on
Web Languages and StandardsPHPScripting Languages
10 Comments1 Solution1972 ViewsLast Modified:
I have the following PHP code which is working fine, but all of the sudden it does not work:
<?php
 header('Content-Type: text/html; charset=utf-8');
$page_id = 'cnninternational';
$access_token = 'xxxxxxx';
//Get the JSON
$json_object = file_get_contents('https://graph.facebook.com/'.$page_id.'/posts?access_token='.$access_token.'&format=json');
//Interpret data
$fbdata = json_decode($json_object);
?>

I started to trace and I found that when I var_dump($json_object) I am getting something like this:

       ‚è5×À4#_rß.²¹ÏÀû-«‹hÎ
M´‹”VÎuK6W•Ð
po6¥üv¢p+¡¿S …QáîÀ&âcÛ6:­„6[¡LÖKØãv¡[f-WFNÅ1Y2+¡]t[0°§5„>Nñ¿À;]¤zŽ‰®›T\¿Ù:K¿Å:ÐçÚd»¸®Þ:sŠ‘Œ‘Ì- eP“tá¿åì" õÖj6³Óf¿¿/¿”ÌÇU¿ÉDGC§¦ ûµyÚE÷­ÑÍ6½.òpß
ÊøõNmY—Vívëþ\ÍC¹ƒpäSl
ºœ¯¶*¿\;&çûíÁ¤¿Ç4É´‚Ð×÷¿·ßœ”Á0œ¿Î¿^aé…6¾¶èU¯ ¿T.¾ªŸò-Ïjd·øÏ*»å`  ¿Wèt„¿²­ÝUåë÷S©H‡[Ì4hü•:³¿¦JK:eM]’®2;é É
#”^® &@¿W0½¬'ØÇ3¿y·MicŠé·"[£%~)—I±ˆ¸¡¼8‹\ò5Fu Ý
ÝP‰ÀLö|Zë¿ å5¡áòVI`œc@ ‘L¬";§tÍag?¶¨z‡p˜½˜‘o«°²W [ ’É_Á·‘Û@‹±S%®–o‚Ï?úÆx¥j¿‡â•i=ç­tZ™n›·rCe)·“k¬K‘À¥¡Ó¿¨+ÆwIÕœ|·.Ç5
"_m¿aC¶C2* «—4ð+áÈÃÖmÛÔz1 ‘ñ¤ù’-€±\ÅG€¨f¨¼êAN§ñ¢ÛYî=c,ú$w¿ú[ø å€æà‚ȪXÏj£©{¤%¢
ÀUØ]hç‰Ë0Ò¿B\19P„1{)º%'@_¸ñ¿Ïo­=:®ìgx »Ì
                                                                                                                                                                                
¿¹ '¾z
ýÃøwƒ ¿
œ6U²ó æüƒT¡ï…8 ¿ÜÛ&ˆÛú_èâÃî0ƒ¨u}nÊóU{wß`—²ƒØÍñWÛmÛùÉP %"?’óI¿Á¼–f³:S¤8¾é–¶)¿@F¯¿€bÃDJK+JA›0ß™L
À®Ž   ÔT¢®1q¡aæ–@ù)¦>$Àñôa6E‚2¯.ÁbË>4þöS‰³ålûA:•´Ãîñÿ÷#“³%ãèeòPÂæ±Ó«¾å0dÊ
                                                                                                                                                                                
                                                                                                                                                                                
                                                                                                                                                                                
Ñ.€Î@G‚
} ðMWŒ#õx.Ò 3©¥\ Q
£¿ 0Âöú·8ÿðo¼¨»«hžÙj¬v^‹»mo¬ÚâX—n"ÿ™[,óC¼À
r5q:/T—«*AØx#U/„åP>|žqY¼ztŒbÈê_Ä¿øÜCIþù§ëãë­ç…ýÖ1ža%pÛæ¿_¿_ÜaוÿLàU2⯨ä—}I<‘Üôƒªlt¿GöÇ_‹¤q¿>ê}<½8~+Fë6¯aÁng†žÔC^1 ÌNÙYå):PI,®žä²¾ê
”ä ¿Ùs@É ¹\cQÿ1Jíu(zyC
í;ðj†
¼ZøÿQ3—¿.ø.HkÂzŸóÚ@sØ¿q¡wQw4å²Cæó©¶59ë*“i^G—xÁ†_çþœ~Cï¢Ýw™ãóÌs9kT~þÎ,½
ºÜo@uLË6]¿ë8¯ÚÑS
í8uRÔT%ëq¿¤ù&µ¿¿Jä©Ìhw"Wy?“úkmƒTÃç
                                                                                                                                                                                
                                                                                                                                                                                
ÇDˆ¿1LŽ >ðÕWõXÏC#N:Í
÷¤˜Î'Y´$ï)&ƒ@Ÿ>-!„j%ºŸ:f?Ëå,ÒÖ6iº´XkË(Á)¶Rn¤¥


However when I access the URL:
https://graph.facebook.com/cnninternational/posts?access_token=xxxxx&format=json

I get something like this

{
   "data": [
      {
         "id": "18793419640_246085255559206",
         "from": {
            "category": "Tv network",
            "name": "CNN International",
            "id": "18793419640"
         },
         "message": "If you\u2019re afraid of heights, you might want to avoid stepping into this \u201cvoid\u201d at the top of the French Alps: http://cnn.it/1kzMekv",
         "picture": "http://external.ak.fbcdn.net/safe_image.php?d=AQB_ttzD_Vr9LPOB&w=154&h=154&url=http\u00253A\u00252F\u00252Fi2.cdn.turner.com\u00252Fcnn\u00252Fdam\u00252Fassets\u00252F131225115813-void-tease-story-top.jpg",
         "link": "http://cnn.it/1kzMekv",
         "name": "The eighth wonder of the world? 'Step into The Void'",
         "caption": "edition.cnn.com",
         "description": "If you're scared of heights, then this is not for you.",
         "icon": "http://static.ak.fbcdn.net/rsrc.php/v2/yq/r/SC2ZmEkfI-X.png",
         "privacy": {
            "value": ""
         },
         "type": "link",
         "status_type": "shared_story",
         "created_time": "2014-01-14T15:09:29+0000",
         "updated_time": "2014-01-14T15:22:39+0000",
         "shares": {
            "count": 15
         },
         "likes": {
            "data": [
               {
                  "id": "100000320486234",
                  "name": "Cris Pereira"
               },
               {
                  "id": "1133601526",
                  "name": "Diego Hernandez"
               },
               {
                  "id": "100004287573273",
                  "name": "Nawa Nazeer"
               },

  I have no idea what went wrong the code was working perfectly and all of the sudden it started to do so.