douwa1304 2014-06-18 14:33
浏览 490
已采纳

从php中的字符串中提取日期

I need to extract dates from a string: For example the string is "...period from 06/01/2014 to 06/30/2014". How can I extract these two dates as:

$date1 = "06/01/2014"; 
$date2="06/30/2014";
  • 写回答

2条回答 默认 最新

  • dowdw44426 2014-06-18 14:36
    关注

    like this

    $string = "period from 06/01/2014 to 06/30/2014";
    
    $results = array();
    
    preg_match_all('#\d{2}/\d{2}/\d{4}#', $string, $results);
    
    $date1 = $results[0][0];
    $date2 = $results[0][1];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?