HTML DOM
내에서 값을 찾는 다음 함수가 있습니다.DOM XPath Query에서 잘못된 문자를 모두 이스케이프하려면 어떻게해야합니까?
그것은 작동하지만, 내가 좋아하는 매개 변수 $value
줄 때 그것을 '문자
어떻게 DOM의 XPath 쿼리에서 모든 잘못된 문자를 탈출
을 탈출하고 있지 않기 때문에,Levi's Baby Overall,
그 균열을?
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;
}
당신은 아마 여기에 답변을 찾을거야 : http://stackoverflow.com/questions/4452323/xpath-query-with-single-quote. – matthias
나는 가능하다고 생각하지 않는다, 그는 코드가 모든 DOM의 –