HTML DOM
;内の値を見つける次の関数があります。
$value
それは機能しますが、次のようなパラメーターを指定Levi's Baby Overall,
すると、 , および ' chars をエスケープしないため、クラックします
DOM XPath クエリからすべての無効な文字をエスケープするには?
private function extract($file,$url,$value) {
$result = array();
$i = 0;
$dom = new DOMDocument();
@$dom->loadHTMLFile($file);
//use DOMXpath to navigate the html with the DOM
$dom_xpath = new DOMXpath($dom);
$elements = $dom_xpath->query("//*[text()[contains(., '" . $value . "')]]");
if (!is_null($elements)) {
foreach ($elements as $element) {
$nodes = $element->childNodes;
foreach ($nodes as $node) {
if (($node->nodeValue != null) && ($node->nodeValue === $value)) {
$xpath = preg_replace("/\/text\(\)/", "", $node->getNodePath());
$result[$i]['url'] = $url;
$result[$i]['value'] = $node->nodeValue;
$result[$i]['xpath'] = $xpath;
$i++;
}
}
}
}
return $result;
}