如何查找<;标题>;并且<;表单>;使用xpath查询


How to find <title> and <form> using xpath query

我正在使用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";
        }
    }

但它不起作用——不知道怎么做?

试试这个

$pokemon_row = $pokemon_xpath->query('//title');
$data["title"]="";
if($pokemon_row->length > 0){
    foreach($pokemon_row as $row){
       $data["title"].= $row->nodeValue . "<br/>";
    }
}