Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/268.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何保存xpath查询数据以使用HTML标记保存HTML?_Php_Dom_Xpath - Fatal编程技术网

Php 如何保存xpath查询数据以使用HTML标记保存HTML?

Php 如何保存xpath查询数据以使用HTML标记保存HTML?,php,dom,xpath,Php,Dom,Xpath,我试图理解如何保存查询找到的html字符串,以便访问它的元素 我使用以下查询查找下面的ul列表 $data = $xpath->query('//h2[contains(.,"Hurricane Data")]/following-sibling::ul/li'); <h2>Hurricane Data</h2> <ul> <li><strong>12 items</strong> found, see &l

我试图理解如何保存查询找到的html字符串,以便访问它的元素

我使用以下查询查找下面的ul列表

$data = $xpath->query('//h2[contains(.,"Hurricane Data")]/following-sibling::ul/li');

<h2>Hurricane Data</h2>
<ul>
    <li><strong>12 items</strong> found, see <a href="/link">here</a>for more information</li>
    <li><strong>19 items</strong> found, see <a href="/link">here</a>for more information</li>
    <li><strong>13 items</strong> found, see <a href="/link">here</a>for more information</li>
</ul>

您不需要重新处理数据,只需说保存这个特定节点

foreach($query as $values){    
    $string[] = $doc->saveHTML($values);
}

其中,
$doc
是用作XPath查询基础的文档。

我觉得Nigel太差劲了。谢谢您。
foreach($query as $values){    
    $string[] = $doc->saveHTML($values);
}