hello everybody, i want a way to get all images from a passed url, like digg.com, when you try to submit a new post it gives you about 4 or 3 images to choose a thumb for the post, so i want something like this, something that i can give a limit for images to be showing and resize them, but the most important thing, that when i give a link in a input or something, it give me some images from the url. thanks for anyhelp
<?php /* url of which you want to get images from.. */ $url = "http://forums.digitalpoint.com/showthread.php?t=1711164"; if(preg_match_all("/(<img)\s (src=\"([a-zA-Z0-9\.;:\/\?&=_|\r|\n]{1,})\")/isxmU", file_get_contents($url), $images)){ /* resize image */ $width = "120"; $height = "67"; /* limit number of images shown */ $limit = 2; $i=0; foreach($images[3] as $image_url){ $i++; if($i != $limit){ if(!parse_url($image_url, PHP_URL_HOST)){ $image_url = preg_replace("/$\//", "", $image_url); $image_url = "http://".parse_url($url, PHP_URL_HOST)."/".$image_url; } echo "<img src=\"".$image_url."\" width=\"".$width."\" height=\"".$height."\"><br>"; } } } else { echo "No images found!"; } ?> PHP:
thank you so mush it's working well but can you tell me how can i customize some extension like jpeg jpg gif and png, and there is something else the limit is not working try cnn.com it is going to give you a lot of images, thanks
<?php /* url of which you want to get images from.. */ $url = "http://www.cnn.com"; if(preg_match_all("/(<img)\s (src=\"([a-zA-Z0-9\.;:\/\?&=_|\r|\n]{1,})\")/isxmU", file_get_contents($url), $images)){ /* resize image */ $width = "120"; $height = "67"; /* limit number of images shown */ $limit = 3; $i=0; foreach($images[3] as $image_url){ $i++; if($i == $limit) break; if(!parse_url($image_url, PHP_URL_HOST)){ $image_url = preg_replace("/$\//", "", $image_url); $image_url = "http://".parse_url($url, PHP_URL_HOST)."/".$image_url; } echo "<img src=\"".$image_url."\" width=\"".$width."\" height=\"".$height."\"><br>"; } } else { echo "No images found!"; } ?> PHP: Ok, sorry, limit issue is fixed Can you ellaborate on the 'customize' the file extension part?, do you want to change the file extension or simply want to retrieve the file extension?...
<?php /* url of which you want to get images from.. */ $url = "http://www.cnn.com"; if(preg_match_all("/(<img)\s (src=\"([a-zA-Z0-9\.;:\/\?&=_|\r|\n]{1,}\.(jpg|png))\")/isxmU", file_get_contents($url), $images)){ /* resize image */ $width = "120"; $height = "67"; /* limit number of images shown */ $limit = 3; $i=0; foreach($images[3] as $image_url){ $i++; if($i == $limit) break; if(!parse_url($image_url, PHP_URL_HOST)){ $image_url = preg_replace("/$\//", "", $image_url); $image_url = "http://".parse_url($url, PHP_URL_HOST)."/".$image_url; } echo "<img src=\"".$image_url."\" width=\"".$width."\" height=\"".$height."\"><br>"; } } else { echo "No images found!"; } ?> PHP:
everything is working now but im really sorry for talking so mush, there is a little problem on digg if you going to submit new post with this url villaarts.com it's going to give you two thumbs but if you type in your code villaarts.com it's going to tell you no images found! what do you think these two images are png