{"id":5050,"date":"2013-11-03T05:07:42","date_gmt":"2013-11-02T18:07:42","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=5050"},"modified":"2013-11-03T05:07:42","modified_gmt":"2013-11-02T18:07:42","slug":"phpjavascripthtml-public-json-data-usage-primer-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/phpjavascripthtml-public-json-data-usage-primer-tutorial\/","title":{"rendered":"PHP\/Javascript\/HTML Public JSON Data Usage Primer Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/JSON\/\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"PHP\/Javascript\/HTML Public JSON Data Usage Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/PHP\/JSON\/PHP_JSON_Primer.jpg\" title=\"PHP\/Javascript\/HTML Public JSON Data Usage Primer Tutorial\" \/><\/a><p class=\"wp-caption-text\">PHP\/Javascript\/HTML Public JSON Data Usage Primer Tutorial<\/p><\/div>\n<p>Here is a tutorial that introduces you to the idea that you can use public data sources of JSON data, for instance, to construct informational web applications.<\/p>\n<p>The two big PHP functions of use are:<\/p>\n<ul>\n<li><a target=_blank title='file_get_contents' href='http:\/\/us1.php.net\/file_get_contents'>file_get_contents<\/a><\/li>\n<li><a target=_blank title='json_decode' href='http:\/\/php.net\/manual\/en\/function.json-decode.php'>json_decode<\/a><\/li>\n<\/ul>\n<p>The public data for today&#8217;s <a target=_blank title='click picture' href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/JSON\/\">tutorial<\/a> regarding time zones is derived from data from <a target=_blank title='World Clock Time Zones JSON Data Feeds | GoMashUp.  The one stop shop for mashup.  JSON, XML, RSS feeds.' href='http:\/\/gomashup.com\/cms\/world_clock_timezone'>World Clock Time Zones JSON Data Feeds | GoMashUp.  The one stop shop for mashup.  JSON, XML, RSS feeds.<\/a> for which we give thanks.<\/p>\n<p>Another tool you should have in your armoury for jobs like this is the online JSON validator <a target=_blank title='JSON validator online' href='http:\/\/jsonlint.com\/'>here<\/a>.   It will help show you, as with the case here in this tutorial, that the data emanating from the link you are given may not satisfy json_decode&#8217;s expected data format, especially that derived from the use of file_get_contents.   The line of code &#8230;<\/p>\n<blockquote><p> $json = substr(str_replace(&#8216;]}&#8217;,&#8217;]&#8217;, str_replace(&#8216;{x[&#8216;,'[&#8216;, str_replace(&#8216;&#8221;result&#8221;:&#8217;,&#8221;, str_replace(&#8220;)&#8221;, &#8220;&#8221;, str_replace(&#8220;?(&#8220;,&#8221;&#8221;,$pageContent))))),1);\n<\/p><\/blockquote>\n<p> &#8230; is a reflection of massaging the data you might have to make it suitable for json_decode usage.  So, in practical terms you should try bare bones file_get_contents and json_decode calls for the URL you were given, and think optimistically, but if you run into trouble &#8230;<\/p>\n<ol>\n<li>Type the URL you were given into a web browser address bar and have a look at it<\/li>\n<li>Type the URL you were given into http:\/\/jsonlint.com\/ and have it validated<\/li>\n<li>Understand in your own mind what would be different about 1. to make it suitable<\/li>\n<li>Incorporate findings of 3. into massaging of data between file_get_contents and json_decode<\/li>\n<\/ol>\n<p>Here is a link to some downloadable PHP programming source code which you may want to rename to <a target=_blank title='time_zones.php' href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/JSON\/time_zones.php_GETME\">time_zones.php<\/a><\/p>\n<p>One last tool of interest is the PHP command <a target=_blank title='var_dump' href='http:\/\/php.net\/manual\/en\/function.var-dump.php'>var_dump<\/a> which can be useful to display for the variable on the left hand side of your json_decode statement, like <i>var_dump($json_output)<\/i> in the case of this tutorial.<\/p>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d5050' onclick='var dv=document.getElementById(\"d5050\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?tag=JSON\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d5050' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Here is a tutorial that introduces you to the idea that you can use public data sources of JSON data, for instance, to construct informational web applications. The two big PHP functions of use are: file_get_contents json_decode The public data &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/phpjavascripthtml-public-json-data-usage-primer-tutorial\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,12,37],"tags":[576,652,664,666,932,997,1281,1319],"class_list":["post-5050","post","type-post","status-publish","format-standard","hentry","category-data-integration","category-elearning","category-tutorials","tag-html","tag-javascript","tag-json","tag-json_decode","tag-php","tag-programming","tag-time-zones","tag-tutorial"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/5050"}],"collection":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/comments?post=5050"}],"version-history":[{"count":0,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/5050\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=5050"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=5050"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=5050"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}