我想使用preg_match當前只是爲了檢索1值(在我移動到檢索多個值之前),但是,我沒有運氣。當我執行print_r()時,我的數組中沒有任何內容存儲。PHP - 使用preg_match從網頁上刮掉DIV元素
這裏是我的代碼我試圖至今:
<?php
$content = '<div class="text-right font-90 text-default text-light last-updated vertical-offset-20">
Reported ETA Received:
<time datetime="2017-02-02 18:12">2017-02-02 18:12</time>
UTC
</div>';
preg_match('|Reported ETA Received: <time datetime=".+">(.*)</time>(.*)\(<span title=".+">(.*)<time datetime=".+">(.*)</time></span>\)|', $content, $reported_eta_received);
if ($reported_eta_received) {
$arr_parsed['reported_eta_received'] = $reported_eta_received[1];
}
?>
所需的輸出:
2017-02-02 18:12
我的上述代碼是行不通的。任何關於這方面的幫助將不勝感激。提前致謝。
結帳DOM文檔http://stackoverflow.com/questions/10366458/php-dom-parsing-a-html-list-into-an-array – Nitin