从网址获取图片 [英] fetch images from url

查看:76
本文介绍了从网址获取图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在尝试使用以下代码从url获取图像,但它仅显示一个img,
谁能抗拒此操作

Hi im trying to fetch images from url using below code but it display only one img ,
can any one sujjest how to do this

<?php

//$url="http://www.askmen.com/fine_living/wine_dine_archive_500/520_mezcal-and-tequila.html";

$url="http://en.wikipedia.org/wiki/Wonders_of_the_World";

$url2="";

$html = file_get_contents($url);



preg_match("/<img .+?\/>/",$html, $result);
//print_r($result);
 for($x=0;$x<count($result);$x++)

 {

   echo $result[0];

 }

?>



我已经修改了我的代码,问题是它正在获取所有图像的名称,但不会显示它.
有人可以喝吗?

这是我更新的代码



i have modified my code , the problem is that it is taking names of all images but not going to display it .
can any one have the soln ?

here is my updated code

$url="http://www.annkristinhaugen.no";
$html = file_get_contents($url);

preg_match("/<img .+?\/>/",$html, $result);

$doc=new DOMDocument();
@$doc->loadHTML($html);

$xml=simplexml_import_dom($doc); // just to make xpath more simple
$images=$xml->xpath('//img');
$arr=array();
foreach ($images as $img) {
    $arr[]=$img['src'];
}


 for($x=0;$x<count($arr);$x++)

    {

?>      <?php //echo $arr[$x][0];?>
    <img src="<?php echo $arr[$x][0];?>" width="150" height="150"/>
<?php





}

?>

推荐答案

url ="
url="http://www.askmen.com/fine_living/wine_dine_archive_500/520_mezcal-and-tequila.html";


url =" http://en.wikipedia.org/wiki/Wonders_of_the_World"
url="http://en.wikipedia.org/wiki/Wonders_of_the_World";


url2 =" "
url2="";


这篇关于从网址获取图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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