我正在尝试从以下内容中获取字符串“hinson lou ann”:
<div class='owner-name'>hinson lou ann</div>
当我运行以下命令时:
$html = "http://gisapps.co.union.nc.us/ws/rest/v2/cm_iw.ashx?gid=12339";
$doc = new DOMDocument();
$doc->loadHTMLFile($html);
$xpath = new DOMXpath($doc);
$elements = $xpath->query("*/div[@class='owner-name']");
if (!is_null($elements)) {
foreach ($elements as $element) {
echo "<br/>[" . $element->nodeName . "]";
$nodes = $element->childNodes;
foreach ($nodes as $node) {
echo $node->nodeValue . "\n";
}
}
}
我收到以下错误:
警告:DOMDocument::loadHTMLFile() [domdocument.loadhtmlfile]: htmlParseEntityRef: http://gisapps.co.union.nc.us/ws/rest/v2/cm_iw.ashx?gid=12339中没有名称,行:1在 /home... 在线...
指的是线loadHTMLFILE
。
注意:该文件不是有效的 HTML,它只包含div
标签!什么是我加载了文件然后在body
上面打了 HTML 标签?