how explode country code from number php, i need 1-3 characters from number for country validation. I have array with ( code => country)
, i have script example, but it works only if i explode 1 character, but country code can be 2 or 3 characters too. i know that i can explode by $number = explode(" ", 1 777777);
, but i need full number without additional symbols or spaces.
$number = "1777777";
$we = substr($number, 0, 2);
$countrys = array(
'1' => 'us',
'2' => 'uk',
'3' => 'de',
'44' => 'fi', // dont work if 2 characters..
'123' => 'no' // dont work if 3 characters..
);
$array = "$we";
echo $country = $countrys[$array[0]];
echo "<br>country";
how i can modificate this code? thank you! or any other suggestions?