PHP Worldbank Growth of Merchandise Trade Emoji Flags Tutorial

PHP Worldbank Growth of Merchandise Trade Emoji Flags Tutorial

PHP Worldbank Growth of Merchandise Trade Emoji Flags Tutorial

With Internationalization thoughts fresh in the mind, we decided to revisit PHP Worldbank Growth of Merchandise Trade Tutorial‘s Country by Country “Growth of Merchandise Trade” Bubble Chart to see what we now know more about to improve this web application.

And so we wondered whether we could enhance with Emoji Flags. Sounds reasonable, but when we’ve done this in the recent past (eg. Window LocalStorage Client Versus Server Map Tutorial) it’s been with Javascript clientside logic, not PHP serverside code, as is the go with our Google Chart Bubble Chart interfacing. Well, here’s our approach (making global $flagentity variable filled in with Emoji Flag content as found) here …

<?php

$flagentity=""; // global here and two below
$lri=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"];
$dri=["U+1F1E6","U+1F1E7","U+1F1E8","U+1F1E9","U+1F1EA","U+1F1EB","U+1F1EC","U+1F1ED","U+1F1EE","U+1F1EF","U+1F1F0","U+1F1F1","U+1F1F2","U+1F1F3","U+1F1F4","U+1F1F5","U+1F1F6","U+1F1F7","U+1F1F8","U+1F1F9","U+1F1FA","U+1F1FB","U+1F1FC","U+1F1FD","U+1F1FE","U+1F1FF"];
$iso_country_codes=['AF','Afghanistan',
'AX','Aland Islands',
'AL','Albania',
'DZ','Algeria',
'AS','American Samoa',
'AD','Andorra', ... ]; // global ... not all shown

function uvaltosfcp($string) { // thanks to https://stackoverflow.com/questions/1805802/php-convert-unicode-codepoint-to-utf-8
return html_entity_decode(preg_replace("/U\+([0-9A-F]{5})/", "&#x\\1;", $string), ENT_NOQUOTES, 'UTF-8');
}

function flagflag($inctryname) {
global $flagentity, $iso_country_codes, $lri, $dri;
$uretv="";
$flagentity="";
if ($inctryname != "") {
$matchfound=false;
for ($im=1; $im<sizeof($iso_country_codes); $im+=2) {
if (strpos(strtolower($iso_country_codes[$im]), strtolower($inctryname)) !== false) {
for ($jm=0; $jm<sizeof($lri); $jm++) {
if (strtoupper(substr($iso_country_codes[-1 + $im],0,1)) == $lri[$jm]) {
$uretv.=$dri[$jm]; //uvaltosfcp($dri[$jm]);
$matchfound=true;
}
}
for ($jm=0; $jm<sizeof($lri); $jm++) {
if (strtoupper(substr($iso_country_codes[-1 + $im],1,1)) == $lri[$jm]) {
$uretv.=$dri[$jm]; //uvaltosfcp($dri[$jm]);
}
}
$flagentity=uvaltosfcp($uretv); //$uretv;
return $inctryname;
}
}
if ($uretv == "" && !$matchfound) {
for ($im=1; $im<sizeof($iso_country_codes); $im+=2) {
if (strpos(explode(",",strtolower($iso_country_codes[$im]))[0], explode(",",strtolower($inctryname))[0]) !== false) {
for ($jm=0; $jm<sizeof($lri); $jm++) {
if (strtoupper(substr($iso_country_codes[-1 + $im],0,1)) == $lri[$jm]) {
$uretv.=$dri[$jm]; //uvaltosfcp($dri[$jm]);
$matchfound=true;
}
}
for ($jm=0; $jm<sizeof($lri); $jm++) {
if (strtoupper(substr($iso_country_codes[-1 + $im],1,1)) == $lri[$jm]) {
$uretv.=$dri[$jm]; //uvaltosfcp($dri[$jm]);
}
}
$flagentity=uvaltosfcp($uretv); //$uretv;
return $inctryname;
}
}
}
}
return $inctryname;
}

?>

Another “peer integration” issue today too. The resource we’d like to thank regarding today’s work, that being Growth of Merchandise Trade has updated its data set for the year range 2006-2016 and we’d like to maintain this, and the previous 2003-2013 data set, for comparison purposes. The Bubble Chart report is the important thing though, and so a select (dropdown) element, probably “below the fold” for you, facilitates this expansion of functionality.

To try the “how we got there” growth_of_merchandise_trade_2006_2016.php you can click/touch this live run link.


Previous relevant PHP Worldbank Growth of Merchandise Trade Tutorial is shown below.

PHP Worldbank Growth of Merchandise Trade Tutorial

PHP Worldbank Growth of Merchandise Trade Tutorial

We’ve said it before, and (no doubt) we’ll say it again … there are great public data sources out there for you to explore.

As far as international data goes the Worldbank series of statistics is great, so, thanks.

Today we combine the Worldbank data for Growth of Merchandise Trade 2003-2013 with the wonderful Google Chart Bubble Chart to create (52 = (first letters of country name) 26 x 2 (concepts: Exports and Imports)) reporting charts of interest, we hope. Again, as with any reporting subject, it is a personal thing, whether the subject matter of a report is of interest, but you could say that about so many things in life.

So, we offer some PHP source code you could call growth_of_merchandise_trade.php and a live run link as well, the full loading of which requires patience.

Stop Press

Tomorrow we go over what was needed to change PHP code above to be more mobile friendly …

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


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

This entry was posted in eLearning, Event-Driven Programming, 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>