Level 1
May 17, 2015
1
Level 30
DomXPath / DOMDocument search document for keywords and put out
Hi guys -
i am writing a little function to search an html file. Currently the function searches for the keyword "effizienzklasse" but the function should search multiple keywords such as "effizienzklasse" and "energie" and "verbrauch" and return it as an array.
How can i pass multiple keywords to the DomXPath ?
private function getCop()
{
$url = "http://content.copmedia.de/de/1373B284BC381890049E92D324F56DE0S15101503.html";
$result = array();
$dom = new DOMDocument;
$dom->loadHTML(file_get_contents($url));
// find all <div>'s with the class lineData using DomXPath :
$xpath = new DomXPath($dom);
$lineDatas = $xpath->query('//div[contains(@class,"lineData")]');
// add all lineData <div>'s containing the keyword to the $result array :
foreach($lineDatas as $lineData) {
if (strpos(strtolower($lineData->nodeValue), 'effizienzklasse') !== false) {
$result[] = $lineData;
}
}
return $dom->saveHTML($lineData);
}
}
Hope someone could help me .. :)
Please or to participate in this conversation.