Main Content

World Flags in your PHP pages

Archive - Originally posted on "The Horse's Mouth" - 2009-08-10 17:30:36 - Graham Ellis

The world's flags are often used to give a quick visible international indication of countries (sidestepping the issue I had yesterday, where I was translating into ten languages and wanted links to each other language on each page and - well - what IS the Finnish for Italy?)

So I have found an Icon set for free download and installed all the flags - let me test it out by listing (flaggily) the countries I have trained / visited on business/ visited just for pleasure: . But I suspect there are one or two there which you'll find aren't in the common 'vocab'.

I have also added the flags on our "Do you train in my country?" page at http://www.wellho.net/resources/countries.html, having the server (in PHP checking) that we actually HAVE a flag before we try and send it out. Just missing East Timor, Yugoslavia (but we have several of the countries that have come out of YU in the list above!), Zaire (reason unknown), and Antarctica. By adding this dynamic check into PHP, we're able to add flags and take them away without having to go through and change the script line by line ... and without risk of broken image icons! Here is a code snippet (yes, I am using the MaxMind GeoIPLite API and the array of country codes that it gives me!).

$flower = strtolower($GEOIP_COUNTRY_CODES[$k2]).".png";
if (file_exists("$_SERVER[DOCUMENT_ROOT]/flag/$flower")) {
   print "<td class=body><img src=http://www.wellho.net/flag/$flower> ";
} else {
   print "<td class=body>    ";
}


The flags are in the public domain, so there is no requirement for me to attribute them. However, I would like to thank Mark James for providing them here, and I'm going to quote his copyright statement from another of his icon sets, as I like what he does and how he says it: I love to hear of my work being used, feel encouraged to send an email with a link or screen shot of the icons in their new home to mjames at gmail dot com. This work is licensed under a Creative Commons Attribution 2.5 License. This means you may use it for any purpose, and make any changes you like. All I ask is that you include a link back to this page in your credits if possible.