ii 具有以下结构:
<div class="xGh" style="background-image: url('name_file.jpg');"></div>
我需要那个输出:
name_file.jpg
我尝试用它answer,但不适合我:
$img = $xpath->query(substring-before(substring-after(//div[@class='xGh']/@style, "background-image: url('"), "')"));
echo $img->item($i)->nodeValue."<br/>";
看一下错误:
Test Ideone有错误
我的语法有一些错误,我不知道如何是正确的......
sry my english
1)你丢失了包裹 xpath 的引号 - 它是字符串。
2)使用dom xpath,查询返回节点集,而要接收字符串结果,最好使用evaluate
$img = $xpath->evaluate('substring-before(substring-after(//div[@class=\'xGh\']/@style, "background-image: url(\'"), "\')")');
echo $img; // it contains name_file.jpg
demo
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)