I'm trying to get the string "hinson lou ann" out of:
<div class='owner-name'>hinson lou ann</div>
When I run the following:
$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";
}
}
}
I get an error of:
Warning: DOMDocument::loadHTMLFile() [domdocument.loadhtmlfile]: htmlParseEntityRef: no name in http://gisapps.co.union.nc.us/ws/rest/v2/cm_iw.ashx?gid=12339, line: 1 in /home... on line ...
Which refers to the line of loadHTMLFILE
.
Note: The file is not valid HTML it only contains div
tags! What is I loaded the file and then slapped the HTMLbody
tag on it?