I have a string with the following format: city (Country)
and I would like to separate the city and the country and store the values in 2 different variables.
I tried the following and it is working to store the city but not for the country.
<?php
$citysearch = "Madrid (Spain)";
echo $citysearch;
$citylen = strlen( $citysearch );
for( $i = 0; $i <= $citylen; $i++ )
{
$char = substr( $citysearch, $i, 1 );
if ($char <> "(")
{
echo $city. "<br>";
$city = $city .$char;
if ($char == " ")
{
break;
}
}
if ($char <> ")")
{
echo $country. "<br>";
$country = $country .$char;
if ($char == ")")
{
break;
}
}
}
echo "This is the city:" .$city;
echo "This is the country:" . $country;;
?>
Any help would be highly appreciated.