Skip to content

Instantly share code, notes, and snippets.

@petk
Created June 20, 2015 15:34
Show Gist options
  • Save petk/e3e04f994d8a6d80ab6c to your computer and use it in GitHub Desktop.
Save petk/e3e04f994d8a6d80ab6c to your computer and use it in GitHub Desktop.
<?php
$count=0;
$url="http://php.net/iterator_to_array";
$html = file_get_contents($url);
$dom = new DOMDocument;
$dom->loadHTML($html);
//$dom->preserveWhiteSpace = false;
$images = $dom->getElementsByTagName('img');
$array = [];
foreach($images as $image){
$array[]['src'] = $image->getAttribute('src');
}
die(var_dump($array));
foreach ($images as $image) {
$image->getAttribute('src');
$count++;
if($count==5)
break;
}
$arr=array();
foreach ($image as $arr){
echo $arr;
}
$arrlen = count($arr);
echo $arrlen;
for($x = 0; $x < $arrlen; $x++) {
echo $arr[$x];
echo "<br>";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment