findDate() публичный статический Метод

Find Date in a String
Автор: Etienne Tremel
public static findDate ( $string ) : mixed
Результат mixed false if no date found else array: array( 'day' => 01, 'month' => 01, 'year' => 2012 )
Пример #1
0
 /**
  * 
  * @param string $token
  * @return false|\DateTime
  */
 public function filter($token)
 {
     $date = Text::findDate($token);
     if (!empty($date) && $this->verify($date)) {
         return new DateTime("{$date['year']}-{$date['month']}-{$date['day']}");
     }
     return false;
 }
Пример #2
0
 /**
  * @return DateTime[]
  */
 public function getDates()
 {
     // return the cached copy
     if (empty($this->dates)) {
         $getDateFunc = function ($sentence) {
             $date = Text::findDate($sentence);
             return new DateTime("{$date['year']}-{$date['month']}-{$date['day']}");
         };
         $this->dates = array_map($getDateFunc, $this->sentences);
         // re-index so nulls and offsets are correct.
         $this->dates = array_values(array_filter($this->dates));
     }
     return $this->dates;
 }