我正在尝试构建一个简单的图像处理程序来从网站中删除某些图像,但到目前为止我所拥有的所有图像都已擦除所有图像
<?php
$url = "http://www.techbuy.com.au/";
$html = file_get_contents('http://www.techbuy.com.au/');
$dom = new domDocument;
$dom->loadHTML($html);
$dom->preserveWhiteSpace = false;
$images = $dom->getElementsByTagName('img');
foreach ($images as $image)
{
$fimage = $image->getAttribute('src');
echo "<img src='$url" . "$fimage' ></img>";
}
?>
如何让它说废弃第二张图片并留下其余图片
答案 0 :(得分:2)
if ($images->length >= 2) { $src = $images->item(1)->getAttribute("src"); }
答案 1 :(得分:2)
<?php
$url = "http://www.techbuy.com.au/";
$html = file_get_contents('http://www.techbuy.com.au/');
$dom = new domDocument;
$dom->loadHTML($html);
$dom->preserveWhiteSpace = false;
$images = $dom->getElementsByTagName('img');
foreach ($images as $key => $image)
{
if ($key === 1) {
$fimage = $image->getAttribute('src');
echo "<img src='$url" . "$fimage' ></img>";
}
}
?>
抓住第二张图片。