Php 使用xpath从背景图像样式属性中提取值
Ii具有以下结构:Php 使用xpath从背景图像样式属性中提取值,php,dom,xpath,Php,Dom,Xpath,Ii具有以下结构: <div class="xGh" style="background-image: url('name_file.jpg');"></div> 查看错误: 错误测试 我在这方面有一些错误,我看不出怎么是正确的 sry my english1)您丢失了包装xpath的引号-它是字符串 2) 使用dom xpath,查询返回一组节点,而要接收字符串结果,最好使用evaluate $img = $xpath->evaluate('substring-
<div class="xGh" style="background-image: url('name_file.jpg');"></div>
查看错误:
错误测试
我在这方面有一些错误,我看不出怎么是正确的
sry my english1)您丢失了包装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
前面的子字符串(后面的子字符串(//div[@class='xGh']/@style,“背景图像:url('”)”)”)
对我来说很好。错误消息是什么?嗯:语法错误,C:\xampp\htdocs\bd_all\sp\sp_C.php中的意外“echo”(T_echo),第22行>>echo$img->item($i)->nodeValue。“
”
@Andersson你能帮我找到那个错误吗,或者用对你有用的代码做一次测试吗?
$img = $xpath->evaluate('substring-before(substring-after(//div[@class=\'xGh\']/@style, "background-image: url(\'"), "\')")');
echo $img; // it contains name_file.jpg