本文整理匯總了PHP中SimpleXMLElement::XPath方法的典型用法代碼示例。如果您正苦於以下問題:PHP SimpleXMLElement::XPath方法的具體用法?PHP SimpleXMLElement::XPath怎麽用?PHP SimpleXMLElement::XPath使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類SimpleXMLElement
的用法示例。
在下文中一共展示了SimpleXMLElement::XPath方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: foreach
}
}
}
if ($keywordId = $search->searchKeyword($keyword, $keywordsXML)) {
//Searchs keyword in list and returns 'ID', if exists;
$databaseXML = simplexml_load_file("../data/database/{$keyword['0']}.xml");
$links = $databaseXML->XPath("/data/keyword[@id={$keywordId}]");
// print_r($links);
foreach ($links[0]->children() as $link) {
$att = 'id';
$urlID = $link->attributes()->{$att};
$att = 'domain';
$domainID = $link->attributes()->{$att};
$att = 'occur';
$occurrence = $link->attributes()->{$att};
if (!($result = $xml->XPath("/results/result[url/@id = {$urlID} and url/@domain = {$domainID}]"))) {
//Insert new result;
$new_result = $xml->addChild('result');
$new_result->addChild('title');
$url = $new_result->addChild('url');
$url->addAttribute('id', $urlID);
$url->addAttribute('domain', $domainID);
$weight = $new_result->addChild('weight');
$words = $new_result->addChild('words');
$word = $words->addChild('word', $keyword);
$word->addAttribute('count', $occurrence);
} else {
//Modify old result;
$words = $result[0]->words;
$word = $words->addChild('word', $keyword);
$word->addAttribute('count', $occurrence);