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