<?php/*
note:
this is just a static test version using a hard-coded countries array.
normally you would be populating the array out of a databasethe returned xml has the following structure
<results>
<rs>foo</rs>
<rs>bar</rs>
</results>
*/ $aUsers = array(
"001426, €0,0211, USA",
"001580, €0,0211, USA",
"001809204, €0,1783, Dominican Republic-Mobile","0037517, €0,3612, Belarus-Minsk",
"00375259, €0,287, Belarus-Mobile",
"0037529, €0,287, Belarus-Mobile",
"00376, €0,0578, Andorra",
"003763, €0,3008, Andorra-Mobile",
"003764, €0,3008, Andorra-Mobile",
"003766, €0,3008, Andorra-Mobile",
"00377, €0,0437, Monaco","001760, €0,0211, USA",
"001761, €0,0211, USA",
"001763, €0,0211, USA",
"001764, €0,0211, USA",
"001765, €0,0211, USA",
"001767, €0,3898, Dominica",
"001768, €0,0211, USA",
"001769, €0,0211, USA",
"001770, €0,0211, USA",
"001772, €0,0211, USA",
"001773, €0,0211, USA",
"001774, €0,0211, USA",
"001775, €0,0211, USA",
"001776, €0,0211, USA",
"001778, €0,0125, Canada",
"001779, €0,0211, USA",
"001780, €0,0125, Canada",
"001781, €0,0211, USA",
"001784, €0,3797, St Vincent Grenadines",
"001785, €0,0211, USA",
"001786, €0,0211, USA",
"001787, €0,0264, Puerto Rico",
"001789, €0,0211, USA",
"001800, €0,0211, USA",
"001801, €0,0211, USA",
"001802, €0,0211, USA",
"001803, €0,0211, USA",
"001804, €0,0211, USA",
"001805, €0,0211, USA",
"001806, €0,0211, USA",
"001807, €0,0125, Canada",
"001808, €0,0274, USA-Hawaii",
"001809, €0,2117, Dominican Republic",
"001809201, €0,1783, Dominican Republic-Mobile",
"001809203, €0,1783, Dominican Republic-Mobile",
);


$aInfo = array(

);


$input = strtolower( $_GET['input'] );
$len = strlen($input);


$aResults = array();

if ($len)
{
for ($i=0;$i<count($aUsers);$i++)
{
// had to use utf_decode, here
// not necessary if the results are coming from mysql
//
if (strtolower(substr(utf8_decode($aUsers[$i]),0,$len)) == $input)
$aResults[] = array( "id"=>($i+1) ,"value"=>htmlspecialchars($aUsers[$i]), "info"=>htmlspecialchars($aInfo[$i]) );

//if (stripos(utf8_decode($aUsers[$i]), $input) !== false)
// $aResults[] = array( "id"=>($i+1) ,"value"=>htmlspecialchars($aUsers[$i]), "info"=>htmlspecialchars($aInfo[$i]) );
}
}





header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified
header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header ("Pragma: no-cache"); // HTTP/1.0



if (isset($_REQUEST['json']))
{
header("Content-Type: application/json");

echo "{\"results\": [";
$arr = array();
for ($i=0;$i<count($aResults);$i++)
{
$arr[] = "{\"id\": \"".$aResults[$i]['id']."\", \"value\": \"".$aResults[$i]['value']."\", \"info\": \"\"}";
}
echo implode(", ", $arr);
echo "]}";
}
else
{
header("Content-Type: text/xml"); echo "<?xml version=\"1.0\" encoding=\"UTF-8\" ?><results>";
for ($i=0;$i<count($aResults);$i++)
{
echo "<rs id=\"".$aResults[$i]['id']."\" info=\"".$aResults[$i]['info']."\">".$aResults[$i]['value']."</rs>";
}
echo "</results>";
}
?>