dpwtr666638 2014-06-25 03:29
浏览 60
已采纳

从RSS描述中提取日期

I need to extract the date from a description which is displayed on an RSS Feed (Workopolis)

Here's an example of a feed item:

<item>
  <guid isPermaLink="true">http://www.workopolis.com/jobsearch/job/15161566?uc=?RSS=Y</guid>
  <link>http://www.workopolis.com/jobsearch/job/15161566?uc=?RSS=Y</link>
  <title>Financial Services Representative</title>
  <description>&lt;strong&gt;Location:&lt;/strong&gt; Barrie, Ontario; Owen Sound, Ontario; Port Elgin, Ontario&lt;br&gt;&lt;strong&gt;Job Category:&lt;/strong&gt; Sales and Business Development &lt;br&gt;&lt;strong&gt;Job Industry:&lt;/strong&gt; Financial Services and Banking&lt;br&gt;&lt;strong&gt;Career Level:&lt;/strong&gt; &lt;br&gt;&lt;strong&gt;Position Type:&lt;/strong&gt; Full Time&lt;br&gt;&lt;strong&gt;Date Posted:&lt;/strong&gt; 06/19/2014&lt;br&gt;&lt;strong&gt;Company Name:&lt;/strong&gt; CIBC&lt;br&gt;&lt;strong&gt;Company URL:&lt;/strong&gt; &lt;a href="http:// "&gt;http:// &lt;/a&gt;</description>
</item>

I've been doing research for about.. 2 hours now. I'm not strong on my more advanced PHP coding, so I could really use some help. The date is in DD/MM/YY inside of .

I guess my question is: How do I extract the date in DD/MM/YYYY and turn it into a $date variable?

Thanks!

  • 写回答

1条回答 默认 最新

  • dsafew1231 2014-06-25 03:43
    关注

    You could use preg_match with a regex pattern tailored specifically for the date:

    \d{2}\/\d{2}\/\d{4}
    

    code:

    $str = '<item>
      <guid isPermaLink="true">http://www.workopolis.com/jobsearch/job/15161566?uc=?RSS=Y</guid>
      <link>http://www.workopolis.com/jobsearch/job/15161566?uc=?RSS=Y</link>
      <title>Financial Services Representative</title>
      <description>&lt;strong&gt;Location:&lt;/strong&gt; Barrie, Ontario; Owen Sound, Ontario; Port Elgin, Ontario&lt;br&gt;&lt;strong&gt;Job Category:&lt;/strong&gt; Sales and Business Development &lt;br&gt;&lt;strong&gt;Job Industry:&lt;/strong&gt; Financial Services and Banking&lt;br&gt;&lt;strong&gt;Career Level:&lt;/strong&gt; &lt;br&gt;&lt;strong&gt;Position Type:&lt;/strong&gt; Full Time&lt;br&gt;&lt;strong&gt;Date Posted:&lt;/strong&gt; 06/19/2014&lt;br&gt;&lt;strong&gt;Company Name:&lt;/strong&gt; CIBC&lt;br&gt;&lt;strong&gt;Company URL:&lt;/strong&gt; &lt;a href="http:// "&gt;http:// &lt;/a&gt;</description>
    </item>';
    
    preg_match("/\\d{2}\/\\d{2}\/\\d{4}/u", $str, $date);
    
    echo $date[0];
    

    output:

    06/19/2014
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch