PHP Simple HTML DOM Parser - 获取元素的连字符属性值 [英] PHP Simple HTML DOM Parser - get element's hyphenated attribute value
本文介绍了PHP Simple HTML DOM Parser - 获取元素的连字符属性值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 PHP 简单 HTML DOM 解析器.在我想解析图像的页面中,'src' 属性被替换为 'data-src'.因此,如果我尝试使用以下代码获取图像路径,它将不返回任何内容:
I'm using PHP Simple HTML DOM Parser. In the page which I want to parse the images 'src' attribute is replaced with 'data-src'. So, if I try to get the image path using the following code, it will return nothing:
$elimage = $offer->find('div.photo', 0);
$im = $elimage->last_child('a');
$img = $im->last_child('img');
$item['image'] = $img->src;
我试过这样做,但它也不起作用:
I've tried to do it like this, but it does not work either:
$elimage = $offer->find('div.photo', 0);
$im = $elimage->last_child('a');
$img = $im->last_child('img');
$item['image'] = $img->data-src;
有人知道这是否可以获取自定义属性的值,如果可以,如何实现?
Does anybody know if that's possible to get the value of a custom attribute and, if yes, how can that be achieved?
感谢您的帮助!
推荐答案
<?php
$str= "<a data-src='http://google.com'>Hello</a>";
$var=preg_split("/data-src=\'/",$str);
//echo $var[1];
$var1=preg_split("/\'/",$var[1]);
echo $var1[0];
?>
你也可以用这个..
这篇关于PHP Simple HTML DOM Parser - 获取元素的连字符属性值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文