PHP/Javascript/HTML Public JSON ASX Usage Tutorial

PHP/Javascript/HTML Public JSON ASX Usage Tutorial

PHP/Javascript/HTML Public JSON ASX Usage Tutorial

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. Today we look at ASX (Shares) informational on the Australian Stock Exchange.

The two big PHP functions of use are:

The public data for today’s tutorial regarding ASX share data is derived from data from Australian%20Securities%20Exchange%20ASX%20Code%20JSON%20Data%20Feeds | GoMashUp. The one stop shop for mashup. JSON, XML, RSS feeds. for which we give thanks.

Another tool you should have in your armoury for jobs like this is the online JSON validator here. 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’s expected data format, especially that derived from the use of file_get_contents. The line of code …

$json = substr(str_replace(‘industry-group’,’industrygroup’, str_replace(‘company-name’,’companyname’, str_replace(‘]}’,’]’, str_replace(‘{x[‘,'[‘, str_replace(‘”result”:’,”, str_replace(“)”, “”, str_replace(“?(“,””,$pageContent))))))),1);

… 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 …

  1. Type the URL you were given into a web browser address bar and have a look at it
  2. Type the URL you were given into //jsonlint.com/ and have it validated
  3. Understand in your own mind what would be different about 1. to make it suitable
  4. Incorporate findings of 3. into massaging of data between file_get_contents and json_decode

Here is a link to some downloadable PHP programming source code which you may want to rename to asx_look.php

At most times when there is the combination of PHP and Javascript, it is the Javascript embellishments that make the application marketable and salesworthy, and so it is here, in this tutorial, with the ASX Search and Google Image Search windows created via:

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 here.

One last tool of interest is the PHP command var_dump which can be useful to display for the variable on the left hand side of your json_decode statement, like var_dump($json_output) in the case of this tutorial.

If this was interesting you may be interested in this too.

This entry was posted in Data Integration, eLearning, Tutorials and tagged , , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>