即使我試圖只得到的的preg_match讓我整個頁面的內容,而不是特定的div
<div class="description">...</div>
它返回我這個特定的div下的所有內容。我怎樣才能得到它之間的內容?
$file_string = file_get_contents('');
preg_match('/<div class="description">(.*)<\/div>/si', $file_string, $description);
$description_out = $description[1];
echo $description_out;
我建議你使用類似[phpQuery](http://code.google.com/p/phpquery/)而不是正則表達式 - 它更易於使用,並且具有更高的內存效率。 – Alfo 2012-07-31 14:50:31
或者,而不是添加一個額外的抽象層,只是用'DOMDocument'或類似 – 2012-07-31 14:58:40