Php 如何使用url获取多个图像

Php 如何使用url获取多个图像,php,curl,Php,Curl,如何使用下面的脚本获取多个图像 <?php $url = 'http://stackoverflow.com/questions/7994340/how-can-i-get-image-from-url-in-php-or-jquery-or-in-both'; $data = file_get_contents($url); if(strpos($data,"<img")) { $imgpart1 = explode('<img src=',$data);

如何使用下面的脚本获取多个图像

<?php
$url = 'http://stackoverflow.com/questions/7994340/how-can-i-get-image-from-url-in-php-or-jquery-or-in-both';
$data = file_get_contents($url);

if(strpos($data,"<img"))
{
    $imgpart1 = explode('<img src=',$data);
    $imgpart2 = explode('"',$imgpart1[1]);
    echo "<img src=".$imgpart2[1]." />";
}
?>

如果您想使用HTML/DOM解析器进行此操作,则它不是用于正则表达式或字符串搜索的作业

我喜欢PHP,它不太难使用

$url = 'http://stackoverflow.com/questions/7994340/how-can-i-get-image-from-url-in-php-or-jquery-or-in-both';
$data = file_get_contents($url);

$dom = new DOMDocument;
// I usually say to NEVER use the "@" operator,
// but everyone's HTML isn't perfect, and this may throw warnings
@$dom->loadHTML($data);

$img = $dom->getElementsByTagName('img');
foreach($img as $x){
    echo $x->getAttribute('src');
}

我建议使用解析HTML,verus使用字符串搜索。完善它的工作原理。。非常感谢你的帮助。其他开发人员也为我花了时间。谢谢