我正在尝试使用Simple HTML DOM从子信息中获取日期01/08/14
。
我的代码是:
HTML:
<div id="display_cr" class="loose-spacing tid">
<div class="review_by">By <strong>juand1</strong> on 01/08/14 06:51 AM (PST)</div>
<div class="review_by">By <strong>juand1</strong> on 01/08/14 06:51 AM (PST)</div>
</div>
PHP:
protected function scrap_date($review) {
$res = '';
$date = $review->find('div[class=review_by]');
if (isset($date)) {
foreach ($date as $div) {
$data = '';
foreach ($review->find('div[class=review_by]') as $element) {
$data = $element->outertext;
}
$res[] = $data;
}
}
return $res;
}
答案 0 :(得分:0)
尝试
foreach ($review->find('div[class=review_by]') as $element) {
$data = $element->innertext;
preg_match("/[0-9]{1,2}\/[0-9]{1,2}\/[0-9]{1,2}/", $data ,$match);
if(sizeof($match) > 0 ){
res[] = $match[0];
}
}