xPath 帮助 > 使用 alt='My Keyword' 查找 img

Sco*_*t B 2 xpath domdocument

如何更改此 xpath 以查找内容是否包含带有包含我的关键字词组的 alt 的 img 标签?

$xPath->evaluate('count(/html/body//'.$tag.'[contains(.,"'.$keyword.'")])');

Dim*_*hev 5

使用

boolean(//img[contains(@alt, 'yourKeywordHere')])
Run Code Online (Sandbox Code Playgroud)

查找 ( true(), false()) imgXML 文档中是否存在其alt属性包含的元素'yourKeywordHere'

使用

boolean(//yourTag//img[contains(@alt, 'yourKeywordHere')])
Run Code Online (Sandbox Code Playgroud)

查找名为的文档中是否有一个元素yourTag具有imgalt属性包含'yourKeywordHere'.