使用xpath从背景图像样式属性中提取值 [英] Extract value from background-image style attribute with xpath

查看:510
本文介绍了使用xpath从背景图像样式属性中提取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Ii具有以下结构:

<div class="xGh" style="background-image: url('name_file.jpg');"></div>

我需要该输出:

name_file.jpg

我尝试使用 answer ,但对我不起作用:

I try use that answer, but dont work fo me :

$img = $xpath->query(substring-before(substring-after(//div[@class='xGh']/@style, "background-image: url('"), "')"));    

echo $img->item($i)->nodeValue."<br/>";

查看错误:

测试< a href = https://ideone.com/NoSAAE rel = nofollow noreferrer> Idone 错误

我在那个sintaxe中有一些错误我看不出正确的方法...

I have some error in that sintaxe i cant see how is correct...

说我的英语

推荐答案

1)您丢失了包装xpath的引号-它是字符串。

1) You lost quotes wrapping xpath - it's string.

2)和dom xpath,查询返回节点集,而要接收字符串结果,最好使用 evaluate

2) with dom xpath, query returns set of nodes while to receive string result it's better to use evaluate

$img = $xpath->evaluate('substring-before(substring-after(//div[@class=\'xGh\']/@style, "background-image: url(\'"), "\')")');    

echo $img; // it contains name_file.jpg

演示

这篇关于使用xpath从背景图像样式属性中提取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆