I am trying to create a function that will return text that indicates date. For example, "today" is the text in following sentence which indicates date.
"I want to meet with you today".
Following functions serve the task except for few words like "I can" "u can" etc. Can anyone tell me why it returns "I can" as date text? any solution?
public function date_text($text, $offset, $length){
$parseArray = preg_split( "/[\s,.]/", $text);
$dateTest = implode(" ", array_slice($parseArray, $offset, $length == 0 ? null : $length));
$date = strtotime($dateTest);
if ($date){
return $dateTest;
}
//make the string one word shorter in the front
$offset++;
//have we reached the end of the array?
if($offset > count($parseArray)){
//reset the start of the string
$offset = 0;
//trim the end by one
$length--;
//reached the very bottom with no date found
if(abs($length) >= count($parseArray)){
return false;
}
}
//try to find the date with the new substring
return $this->date_text($text, $offset, $length);
}