If the user input is ,for example
"house Seattle job" and you wanna get the Seattle word, you can do this with explode
http://www.php.net/manual/en/function.explode.php
php if($_GET['KEY'] == "")
{
// no keyword entered
echo "";
}
else
{
$userCity=array();
$userCity=explode(" ",$_GET['key']);
Now you must loop through the userCity array and compare with another array or with what you used to store the city names
Here you must have a convetion.All the citynames must be in lower/uppercase in order to get a good comparison . So you must do an additional operation before using the for : $userInputCity=strtolower($_GET['key']) assuming that the names in cities array are also lowercase
foreach($userCity as $key1 => $inputcity)
{
foreach($cities as $key2 => $cityname)
{
if($inputcity == $cityname)
echo 'found a city';
}
}
If the input city name is composed of a single word , this would work fine , but if is something like New York , Los Angeles than in the for loop you must add :
elseif($key1 != 0 )
{
$twoWordCity=$userCity[$key1-1]." ".$userCity[$key1];
if( $twoWordCity == $cityname )
echo 'found a city';
}
Later edit :
After a second thought , it's much easier to just use the strpos() , like this :
$myCityNamesArray=('london','new york','sydney',......);
$cityInput=strtolower($_GET['key']);
foreach($myCityNamesArray as $cityName )
{
if( strpos( $cityInput , $cityName ) !== false )
{
echo 'found it ';
break;
}
}