PHP - read correct file content from a .json file (url)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
neva
Forum Newbie
Posts: 2
Joined: Mon Jul 20, 2009 9:22 pm

PHP - read correct file content from a .json file (url)

Post by neva »

Hello!

I'm new in this forum and new to PHP as well. :D
I already finished my first snapplets and enjoy learning PHP but right now I'm having issues with the following code:

Code: Select all

<?php
 
$Content = readfile("http://documentstat.issuu.com/090707215954-95c72a760f1d4248a6566f3e70e4ab6a/document_statistics.json");
echo $Content;
 
?>
The link

Code: Select all

http://documentstat.issuu.com/090707215 ... stics.json
itself works well in the browser and shows me a json content but if I run the php code the output looks like this:

Code: Select all

‹­[KoG ¾çW:µ@R 9¯]Ÿ ôÔKQ4n-Šb-¯Á²H²}üß;Ú‡d‹üä ˜Ààٝù–3äÇÇÐÛ]³Ûþ7o–Ëëf~÷Ã×ÙÍzþpß®v˃Åv·˜og—_ß]\Ì~~l7ÛÅzU~ŸÑì}74¾ýëÍ~ÔÕ.»Ìë>Ôqž¹ÉÉÝÒMàP5)¦tëÛìÚÐ\§f\¡Ùµ¿¬—Ëv¾k»EعúƒËåçʹËîç'çÜßÃûËf»ûóË~Ö«·Ù]1_Òéۏ‹öi/À,Ö™_Žý¾YŸ ?mÿ_¦ŠÓëÑáõ®×ë»ûfs·ý£·‹Çþk¸/_šOm7ñj½k–ÝÔÚ—}9}<®[;ïBÿpÿlÿÿ”_.ºßÿëçüöpÜý~ø aÈ>ŸŽË‡äÝ‹G‡Oï60κÏï1«xÁ{„çC„xoÉeû5ëá<#8÷6œX¶äP#8ª+GoÃE.A阃Aº¤Áq„ p\³7À ì× H:®T• p• —ÒLÎ&é„Jtk¦nfŠ–³#§âÅ Š#4ô)x*±pt‚F¼-–G*±àaùÈ´Ÿ€_*äÿŠiB¼)òéüa~DÑ”?H½ï£nŒ²Å?È8¬_TòêÏÄ/Açåóòç„ó :¿xìÿ|°ØŸ¬ ô‹ÂÂyÛ~êüâe\sÀ3U'‚Î/\Cûã ýí„™äÉ~QìoÇ/SôEç®à~r2ŸÎ/gå³øÛ¨ó ˸ô€çL¥A_XæiG<‹~F_p½ è§…¯£Î/\A~1âéüÂúw[½ êü‚ëÏ$ŸÎ/óKÈP?'ð‹ôý¢øüŽ'¦È§ó ®–O1ŸÎ/¡FõOcÄ/°þRÎÏ¢ŸIç—ë/ðÅÑ<_®O¼¾Ãúf<¿dOD‹?J ~Éм©ž%Ïiò§7ÕC’Î/>ÁøÚ›î;’Î/^æ…ß'þ”r ñ'ŽçÅþ¤^ôNçÓlªOd¿È¼âˆgºlñ ¼¯"ª,ùJÖù…*¨ŸdòYç’q÷ÏT‘¼5àA{ ¶ØCù‘¬«ô…,õÈ ò#ìØ&ȏ°ÿcìÿ&äåGX¾`ÙOy6, íM2ŽV’¼“ó³Ø{øEòÜ/šº@~$ýâñü,ö.㾁?aÁûð‚g±?YçâAšzmd4àÁx0ØôSç— ýÔ1Þ5é ȏ°&¾–u%)9‘Ïʺêp~ÐßS¼$óÊ!Ãùm0áüÇgÁtß(;öÞ>?“¾èüä½ÒQ>“¾~ígåSLçøåŒý±ÅßÖ€_p?ƒ¯,üRƒü×—|²õ×éãaL‰¯m€:ÃxÙÉq4u ÉTèm—kqñä@ #{Ó¾ H’¤±“2S“–ì®éW•Õæc–­~BTON§E™F@—-aÉþ½~v`“3ÝëÓ‰ÆÁF×r6@ipgXQ3K¤Fz+o‘j©K¶V^i®8S,Cz3oÙi¬¥6¥Ñ»yË–B¦±n)`œ.9|Ý2 Pgš³farOzCoÔã…Rùÿßý+³Ý¦¹½]Ì?®6sõO\VÍ}»Ÿù°º[­ŸV/þ¼Øuk†ýêrŒ“ÛíÃ2µë-;?õf±iç;e.];?uÓÞ¶›ÍbõI™ÐÕÚ8yÛ6›ùg ÷ž{~þñç¿Q®51593
And I have no idea how to fix that :)

Of course I tried several things like file() or file_get_contents () but the output is messed up in either way.

I suspect it could have something to do with UTF and such? Because when I copy the content from the browser window and paste it into a .txt/.json file and open this with the same code but from my local harddrive it works well. My goal is to open the file from the URL and to work with the content in arrays and such.

I dont expect a ready made solution but hints in which direction I should go are much appreciated! :)

EDIT: I work with PHP Version 5.2.9
neva
Forum Newbie
Posts: 2
Joined: Mon Jul 20, 2009 9:22 pm

Re: PHP - read correct file content from a .json file (url)

Post by neva »

Hello McInfo!

Thanks so much for your advice!

It works so well! With these specific keywords I found out how to restore it even as a file for later use :D

And by using the seach in this forum I even got to fix this: "Fatal error: Call to undefined function curl_init()" 8)

Thanks again! Im really excited about learning more!

neva
Post Reply