i have a string “9 bedrooms in that house”, but it could be anything else, but bedroom keywords will stay (bed, beds, bedrooms, bedroom, etc.) <- this is $search_array variable
i have converted it into an array using explode
i need to find a word bedroom and to see if there is a number beside it.
assuming my array after explode is – (9, bedrooms, in, that, house), how can i check for a number beside it
i have used that code below and its inside a function hence $array =& $this->search_array
if($array =& $this->search_array){
$bedroom_keywords = array('bed', 'beds', 'bedroom', 'bedrooms');
foreach($this->bedroom_keywords as $beds)
{
// if successful in assigning key find a
// number in next and previous positions
if($key = array_search($beds, $array))
{
if($next = $array[$key+1])
{
echo $next;
}
elseif($prev = $array[$key-1])
{
echo $prev;
}
}
}
}
but im getting this error:
Notice: Undefined offset: 2 in /Users/User/Sites/parser.php on line 92 9ad_type:
when i use just 2 tokens ie – “9 beds”.
is there any way i can check if there is a next/previous value in the array or do something so it’ll work?
thanks
You could use a regular expression for this task:
will find a number with at lease one digit, then any number of spaces, then one of those bed words.