<?php
$Ucountries = ["Uganda",
"Ukraine",
"United Arab Emirates (UAE)",
"United Kingdom (UK)",
"United States of America (USA)",
"Uruguay",
"Uzbekistan"];
$Mcountries = ["Macedonia (FYROM)",
"Madagascar",
"Malawi",
"Malaysia",
"Maldives",
"Mali",
"Malta",
"Marshall Islands",
"Mauritania",
"Mauritius",
"Mexico",
"Micronesia",
"Moldova",
"Monaco",
"Mongolia",
"Montenegro",
"Morocco",
"Mozambique",
"Myanmar (Burma)"];
$str = "countries_mexico_mexico_city";
//$str = "countries_united_states_ohio";
$str = str_replace("countries_", "", $str);
// Copy array needed to $CountryList
$CountryList = ${strtoupper(substr($str,0,1)). "countries"};
$countryarr = array();
$arr = explode("_", $str);
Foreach($arr as $val){
Foreach($CountryList as $item){
If(stripos($item, $val) !== false){
If(!in_array($val, $countryarr)){
$countryarr[] = $val;
}
}
}
}
$country = implode(" ", $countryarr);
$state_city = preg_replace("/" . implode("_",$countryarr) . "/", "", $str,1);
$state_city = trim(str_replace("_", " ", $state_city));
Echo $country . "\n" . $state_city;
preferences:
42.72 ms | 413 KiB | 5 Q