jsschmitt Posted July 3, 2009 Share Posted July 3, 2009 Ok... I have been playing with some code I found that pulls the thumbnail from Google images, but I want it to pull more then one image. I know I will need an array, I just can't figure out where to place it. Or maybe a loop? Any help? <?php function google_image ($q) { $q_filter = "*.*"; $q = str_replace ( " " , "+", $q ); $get_data = file_get_contents ("http://images.google.com/images?q=".$q . "+" . $q_filter . "&imgsz=small|medium|large|xlarge&hl=en&sa=G&safe=off&gbv=1"); $exp1 = explode ( "http://tbn", $get_data ); $exp2 = explode ( "width", $exp1[1] ); return "http://tbn" . $exp2[0]; } $image = google_image ("criteria"); echo "<img src='$image'>"; ?> Link to comment https://forums.phpfreaks.com/topic/164681-solved-tweak-code-into-an-array/ Share on other sites More sharing options...
flyhoney Posted July 3, 2009 Share Posted July 3, 2009 This might work: <?php function google_image ($q) { $q_filter = "*.*"; $q = str_replace ( " " , "+", $q ); $get_data = file_get_contents ("http://images.google.com/images?q=".$q . "+" . $q_filter . "&imgsz=small|medium|large|xlarge&hl=en&sa=G&safe=off&gbv=1"); $exp1 = explode ( "http://tbn", $get_data ); $images = array(); foreach ($exp1 as $exp) { $exp2 = explode ( "width", $exp ); $images[] = "http://tbn" . $exp2[0]; } return $images; } $images = google_image ("criteria"); foreach ($images as $image) { echo "<img src='$image'>"; } Link to comment https://forums.phpfreaks.com/topic/164681-solved-tweak-code-into-an-array/#findComment-868444 Share on other sites More sharing options...
jsschmitt Posted July 3, 2009 Author Share Posted July 3, 2009 Thankies! Link to comment https://forums.phpfreaks.com/topic/164681-solved-tweak-code-into-an-array/#findComment-868448 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.