isocountrycodes //[[fradeff@akademia.ch|Fred Radeff]] 2009/06/24 08:54//
<?php /* [[iso_country_search.php]] Script to find a country having his iso code # Authors: # FR, radeff@akademia.ch # History # 2009 / 01 / 13: FR, created ######### */ /* $array = array(0 => 'blue', 1 => 'red', 2 => 'green', 3 => 'red'); $key = array_search('1', $array); // $key = 2; echo "<br>" .$key; $key = array_search('red', $array); // $key = 1; echo "<br>" .$key; */ $pays= array( "AF" => "AFGHANISTAN", ... "ZIMBABWE" => "ZW" ); function array_search_recursive($needle, $haystack, $nodes=array()) { foreach ($haystack as $key1=>$value1) { if (is_array($value1)) $nodes = array_search_recursive($needle, $value1, $nodes); elseif (($key1 == $needle) or ($value1 == $needle)) $nodes[] = array($key1=>$value1); } return $nodes; } ?><!-- now the form --> <form method="GET"> <select name="mode"> <option value="iso" selected>Chercher à partir du code iso</option> <option value="pays">Chercher le code iso à partir du nom du pays</option> </select> <input type="text" name="chercher" value="<? echo $chercher; ?>"> <input type="submit"> </form> <? $mode=$_GET['mode']; $chercher=$_GET['chercher']; #echo $chercher; $chercher=strtoupper($chercher); #echo $chercher; if($mode!="iso"){ $key=array_search($chercher, $pays); } else { $key=array_search($chercher, $pays_iso); } echo "<br>" .$chercher . " - " .$key; ?>