如何从包含可能在php中的日期的strign中提取日期

时间:2016-01-08 06:05:24

标签: php regex

我试过这是代码

$temp = "1|<select class='form-control selectpicker' id='sel_date'
onchange='return GetSessionData(\"2\")'>
   <option>Select Date</option>
   <option value='2016/01/08'>08-Jan-2016</option>
   <option value='2016/01/09'>09-Jan-2016</option>
   <option value='2016/01/10'>10-Jan-2016</option>
   <option value='2016/01/11'>11-Jan-2016</option>
   <option value='2016/01/12'>12-Jan-2016</option>
   <option value='2016/01/13'>13-Jan-2016</option></select>";

   $_date_pattern_two = "/<option value=(/([a-zA-Z]+) (\d+)/>(.*?)/<\/option>";
   preg_match_all($_date_pattern_two, $temp, $_date_match_two);
   var_dump($_date_match_two);exit;

输出我希望数组包含所有日期。 这里 $_date_match_two = ['08-Jan-2016','09-Jan-2016','10-Jan-2016','11-Jan-2016',..];

1 个答案:

答案 0 :(得分:0)

这是你的答案: -

('grain',
  'Thailand exported 84,960 tonnes of rice in the week ended February 24, '
  '689,038 tonnes of rice between the beginning of January and February 24, '
  'up from 556,874 tonnes during the same period last year. It has '
  'commitments to export another 658,999 tonnes this year. REUTER '),
 ('soybean',
  'The Tokyo Grain Exchange said it will raise the margin requirement on '
  'the spot and nearby month for U.S. And Chinese soybeans and red beans, '
  'effective March 2. Spot April U.S. Soybean contracts will increase to '
  '90,000 yen per 15 tonne lot from 70,000 now. Other months will stay '
  'will be set at 70,000 from March 2. The new margin for red bean spot '),.....

<强>输出: -

NSString *namesString = [self.names objectAtIndex:i];
infoWindow.storeAddressLabel.text = [NSString stringWithFormat:@"%@",namesString];