【发布时间】:2014-05-27 13:12:00
【问题描述】:
我正在使用 PHP Simple HTML DOM,但发现它无法从 data-src 属性或 <img src 中读取图像,如果没有 http: 例如; <img src="//static.mysite.com/123.jpg">
有什么方法可以实现吗?
我的代码是:
if($htm->find('img')){
foreach($htm->find('img') as $element) {
$raw = file_get_contents_curl($element->src);
$im = @imagecreatefromstring($raw);
$width = @imagesx($im);
$height = @imagesy($im);
if($width>500&&$height>=350){
$hasimg = '1';
echo '<img src=\'' .$element->src. '\'>';
}
} // end foreach
} // end if htm
【问题讨论】:
-
如果指定
http有什么问题? -
其实问题出在哪里
http:不见了。 -
如果站点没有
http没有响应,则在foreach 循环中手动编写 -
尝试在
file_get_contents_curl(...);之后添加die();var_dump($raw);并验证该功能是否正常工作。我猜你没有得到任何错误,因为所有的错误抑制操作符。 -
它不是站点 URL,它关于远程 URL 上的 img 路径中的
http:。
标签: php