{"id":5075,"date":"2013-11-08T05:05:15","date_gmt":"2013-11-07T18:05:15","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=5075"},"modified":"2013-11-08T05:05:15","modified_gmt":"2013-11-07T18:05:15","slug":"phpjavascripthtml-public-json-data-usage-yet-more-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/phpjavascripthtml-public-json-data-usage-yet-more-tutorial\/","title":{"rendered":"PHP\/Javascript\/HTML Public JSON Data Usage Yet More Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/JSON\/PHP_JSON_YetMore.m4v\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"PHP\/Javascript\/HTML Public JSON Data Usage More Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/PHP\/JSON\/PHP_JSON_YetMore.jpg\" title=\"PHP\/Javascript\/HTML Public JSON Data Usage More Tutorial\" \/><\/a><p class=\"wp-caption-text\">PHP\/Javascript\/HTML Public JSON Data Usage Yet More Tutorial<\/p><\/div>\n<p>Here is a tutorial that builds on the previous <a target=_blank title='PHP\/Javascript\/HTML Public JSON Data Usage More Tutorial' href='#ppjdumt'>PHP\/Javascript\/HTML Public JSON Data Usage More Tutorial<\/a> in introducing you to the idea that you can use public data sources of JSON data, for instance, to construct informational web applications.  Today we make it a bit more functionally recursive by nature in having it call itself to set up the scenario of a from and to destination to introduce the idea of a Google Maps <i>get directions<\/i> scenario.<\/p>\n<p>The Javascript embellishments in this tutorial mainly revolve around:<\/p>\n<ul>\n<li><a target=_blank title='window.open' href='http:\/\/www.w3schools.com\/jsref\/met_win_open.asp'>window.open<\/a><\/li>\n<\/ul>\n<p>The use of window.open can sometimes be blocked by web browsers depending on their settings and you can read a bit more about such issues <a target=_blank title='pop-up windows' href='http:\/\/en.wikipedia.org\/wiki\/Pop-up_ad'>here<\/a>.<\/p>\n<p>The public data for today&#8217;s tutorial&#8217;s <a target=_blank title='click picture' href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/JSON\/time_zones_plus_to.php\">live run<\/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>Here is a link to a <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/JSON\/time_zones_plus_to.php\" title='Live run'>live run<\/a>.<\/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_plus_to.php' href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/JSON\/time_zones_plus_to.php_GETME\">time_zones_plus_to.php<\/a><\/p>\n<hr \/>\n<p id='ppjdumt'>Previous <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=5059\" title='PHP\/Javascript\/HTML Public JSON Data Usage More Tutorial'>PHP\/Javascript\/HTML Public JSON Data Usage More Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/JSON\/time_zones_plus.php\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"PHP\/Javascript\/HTML Public JSON Data Usage More Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/PHP\/JSON\/PHP_JSON_More.jpg\" title=\"PHP\/Javascript\/HTML Public JSON Data Usage More Tutorial\" \/><\/a><p class=\"wp-caption-text\">PHP\/Javascript\/HTML Public JSON Data Usage More Tutorial<\/p><\/div>\n<p>Here is a tutorial that builds on the previous <a target=_blank title='PHP\/Javascript\/HTML Public JSON Data Usage Primer Tutorial' href='#ppjdupt'>PHP\/Javascript\/HTML Public JSON Data Usage Primer Tutorial<\/a> in introducing you to the idea that you can use public data sources of JSON data, for instance, to construct informational web applications.  Today we make it a bit more marketable and interesting with some client side possibilities, when are easy &#8220;add-ons&#8221; to the original PHP <a target=_blank title='file_get_contents' href='http:\/\/us1.php.net\/file_get_contents'>file_get_contents<\/a>\/<a target=_blank title='json_decode' href='http:\/\/php.net\/manual\/en\/function.json-decode.php'>json_decode<\/a> JSON public data ideas.   The good reasoning here, in my view, in that you have done the hard work, so while you are there, you may as well add some flare, or for those &#8220;love-childs&#8221; of the 70&#8217;s &#8230; <a target=_blank title=\"70's flares\" href=\"http:\/\/www.youtube.com\/watch?v=7TPePH2n8tk\">flares<\/a>.  For our tutorial those content embellishments involve <a target=_blank title='Google Maps' href='http:\/\/maps.google.com'>Google Maps<\/a> and the <a target=_blank title='Google Search Engine' href='http:\/\/www.google.com'>Google Search Engine<\/a> image search functionality, and for that brilliant functionality we give thanks.<\/p>\n<p>The Javascript embellishments in this tutorial mainly revolve around:<\/p>\n<ul>\n<li><a target=_blank title='window.open' href='http:\/\/www.w3schools.com\/jsref\/met_win_open.asp'>window.open<\/a><\/li>\n<\/ul>\n<p>The use of window.open can sometimes be blocked by web browsers depending on their settings and you can read a bit more about such issues <a target=_blank title='pop-up windows' href='http:\/\/en.wikipedia.org\/wiki\/Pop-up_ad'>here<\/a>.<\/p>\n<p>Other embellishments revolve around a bit of CSS styling.   These may be simple embellishments, but, as you can see comparing it to the previous tutorial&#8217;s look and feel, it is much more colourful and dynamic, and think it is more interesting with its content and its impact.<\/p>\n<p>The public data for today&#8217;s <a target=_blank title='click picture' href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/JSON\/time_zones_plus.php\">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 eminating 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_plus.php' href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/JSON\/time_zones_plus.php_GETME\">time_zones_plus.php<\/a><\/p>\n<hr \/>\n<p id='ppjdupt'>Previous <a target=_blank title='PHP\/Javascript\/HTML Public JSON Data Usage Primer Tutorial' href='http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=5050'>PHP\/Javascript\/HTML Public JSON Data Usage Primer Tutorial<\/a> is shown below.<\/p>\n<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 eminating 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\/?s=Google+Chart#content\" + \"&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<hr \/>\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='#d5059' onclick='var dv=document.getElementById(\"d5059\"); 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='d5059' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr \/>\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='#d5075' onclick='var dv=document.getElementById(\"d5075\"); 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='d5075' 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 builds on the previous PHP\/Javascript\/HTML Public JSON Data Usage More Tutorial in introducing you to the idea that you can use public data sources of JSON data, for instance, to construct informational web applications. Today &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/phpjavascripthtml-public-json-data-usage-yet-more-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":[527,576,652,932,997,1319],"class_list":["post-5075","post","type-post","status-publish","format-standard","hentry","category-data-integration","category-elearning","category-tutorials","tag-google-maps","tag-html","tag-javascript","tag-php","tag-programming","tag-tutorial"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/5075"}],"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=5075"}],"version-history":[{"count":0,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/5075\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=5075"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=5075"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=5075"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}