Created
June 20, 2015 15:34
-
-
Save petk/e3e04f994d8a6d80ab6c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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