Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/237.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP简单HTML DOM解析器-获取元素';s连字符属性值_Php_Parsing - Fatal编程技术网

PHP简单HTML DOM解析器-获取元素';s连字符属性值

PHP简单HTML DOM解析器-获取元素';s连字符属性值,php,parsing,Php,Parsing,我正在使用PHP简单HTML DOM解析器。在我想要解析图像的页面中,“src”属性被替换为“data src”。因此,如果我尝试使用以下代码获取图像路径,它将不返回任何内容: $elimage = $offer->find('div.photo', 0); $im = $elimage->last_child('a'); $img = $im->last_child('img'); $item['image'] = $img->src; 我尝试过这样做,但也不起作用:

我正在使用PHP简单HTML DOM解析器。在我想要解析图像的页面中,“src”属性被替换为“data src”。因此,如果我尝试使用以下代码获取图像路径,它将不返回任何内容:

$elimage = $offer->find('div.photo', 0);
$im = $elimage->last_child('a');
$img = $im->last_child('img');
$item['image'] = $img->src;
我尝试过这样做,但也不起作用:

$elimage = $offer->find('div.photo', 0);
$im = $elimage->last_child('a');
$img = $im->last_child('img');
$item['image'] = $img->data-src;
有人知道是否可以获得自定义属性的值吗?如果可以,如何实现

谢谢你的帮助

谢谢你的帮助

我使用以下函数从字符串中获取URL:

function checkURL($str) {
    $regex = '$\b(https?|ftp|file)://[-A-Z0-9+&@#/%?=~_|!:,.;]*[-A-Z0-9+&@#/%=~_|]$i';

    preg_match_all($regex, $str, $result, PREG_PATTERN_ORDER);
    $A = $result[0];

    foreach($A as $a) {
        $retval .= $a; 
    }

    return $retval;
}
我找到的URL-s是绝对的,在给定的字符串中只有一个URL


再次感谢您的提示@Rajat Singhal

无论如何,我正要找到解决此类问题的方法,在这里遇到了困难,然后突然有了一个想法

<?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];
?>
先把它放在变量中:

$dataSrc='data-src';
$item['image'] = $img->$dataSrc;
而不是

 $img->data-src;
使用


摘自

Get src by regular expressions form$img感谢您的帮助。使用以下regexp“$\b(https?| ftp |文件)://[-A-Z0-9+&@#/%?=~ |!:,.;]*[-A-Z0-9+&@#/%=~ |]$i”获取源代码。他们有绝对的URL-s。
$img->{'data-src'};