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 International Calling Code information useful when making international phone calls.
The two big PHP functions of use are:
The public data for today’s tutorial regarding ICC share data is derived from data from International Country Calling Codes JSON Data Feed | 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(‘]}’,’]’, 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 …
- Type the URL you were given into a web browser address bar and have a look at it
- Type the URL you were given into http://jsonlint.com/ and have it validated
- Understand in your own mind what would be different about 1. to make it suitable
- 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 international_calling_codes_plus.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 optional International Call Code Country Google Map Search and Google Image Search of Area 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.