我使用xpath query
查找<title>
文字和<form>
的出现次数。我的代码如下
$pokemon_doc = new DOMDocument();
libxml_use_internal_errors(TRUE);
if(!empty($html)){
$pokemon_doc->loadHTML($html);
libxml_clear_errors(); //remove errors for yucky html
$pokemon_xpath = new DOMXPath($pokemon_doc);
$pokemon_row = $pokemon_xpath->query('/title');
if($pokemon_row->length > 0){
$data["title"]="Yes";
}
}
但它不知道如何做到这一点?
答案 0 :(得分:0)
试试这个
$pokemon_row = $pokemon_xpath->query('//title');
$data["title"]="";
if($pokemon_row->length > 0){
foreach($pokemon_row as $row){
$data["title"].= $row->nodeValue . "<br/>";
}
}