esafwan - 你可以使用正則表達式來提取div(特定id)之間的內容。
我之前爲這個圖片標籤做過這個,所以應用了相同的規則。我會查看代碼並稍微更新消息。
[更新]試試這個:
<?php
function get_tag($attr, $value, $xml) {
$attr = preg_quote($attr);
$value = preg_quote($value);
$tag_regex = '/<div[^>]*'.$attr.'="'.$value.'">(.*?)<\\/div>/si';
preg_match($tag_regex,
$xml,
$matches);
return $matches[1];
}
$yourentirehtml = file_get_contents("test.html");
$extract = get_tag('id', 'content', $yourentirehtml);
echo $extract;
?>
或者更簡單地說:
preg_match("/<div[^>]*id=\"content\">(.*?)<\\/div>/si", $text, $match);
$content = $match[1];
吉姆
通過「內容」你的意思是'一些content'或'
一些內容
' 並且評論節點總會被寫入'<! - content - >'? – Gordon 2010-08-04 10:05:03