PHP XPath,无法检索目标标记中标记后的文本
我有这段html代码,要在上面执行xpath:PHP XPath,无法检索目标标记中标记后的文本,php,xpath,Php,Xpath,我有这段html代码,要在上面执行xpath: <b>Random Field:</b> <p> A random field describes an <a href="/index.php?page=glossary&term_id=230"> experiment</a> with outcomes being functions of more than one continuous variable,
<b>Random Field:</b>
<p>
A random field describes an <a href="/index.php?page=glossary&term_id=230">
experiment</a> with outcomes being functions of more than one continuous variable,
for example U(x,y,z), where x, y, and z are coordinates in space. Random field is
extension of the concept of <a href="/index.php?page=glossary&term_id=598">random
process</a> into the case of multivariate argument.
</p>
但它给了我这个:
A random field describes an
我想要的是:
随机场描述..(以此类推)。。多变量参数的定义。
所以我猜问题出在
标签上。因为每次我试图在同一个有图案的文档上执行此操作时,它都会在这个
标记之前停止。
谢谢..这将起作用:
$xpath->query('//p[preceding::b]')->item(0)->textContent;
XPath中有一个
string join
函数,但遗憾的是,PHP使用的lbxml的XPath 1.0版本中没有该函数。谢谢^^^^求值和查询之间有什么区别?第(0)项表示什么?谢谢。evaluate()
将返回一个类型化的结果(节点列表、字符串、整数等)如果可能,->query()
始终返回一个DOMNodeList
,->item(0)
从该列表中获取第一个(0-索引)项,在这种情况下是唯一的(第一个)
元素。如果有更多的
节点需要捕获,您可以通过DOMNodelist循环->query()
返回并连接其中项目的->textContent
。
$xpath->query('//p[preceding::b]')->item(0)->textContent;