我需要从
获得价值<div id = "result">Roll No 103 Pass</div>
和out put应该是:Roll No 103 Pass
我使用了这段代码:
$markup = file_get_contents('www.results.com');
$doc = new DomDocument();
@$file = $doc->loadHTML($markup);
$spans = $doc->getElementsByTagName('div');
foreach($spans AS $span)
{
$class = $span -> getElementsById('id');
if($class=="result") {
echo $span -> nodeValue;
}
}
但它只是返回空白屏幕
答案 0 :(得分:3)
$doc = new DomDocument();
$doc->loadHTMLFile('http://www.results.com');
$thediv = $doc->getElementById('result');
echo $thediv->textContent;
答案 1 :(得分:1)
两个评论:
textContent
[docs]属性获取内部文本。示例:
$div = $doc->getElementById('result');
if($div) {
echo $div->textContent;
}