milly Posted August 3, 2006 Share Posted August 3, 2006 Hi all,I am basically trying to get the image url's of of google image search page, i have got everything to work for one instance of the search but when i try to loop it to do the search for many image searches the arrays will not echo the results.[code]<?php$town = "scarborough";$url = "http://images.google.co.uk/images?q=$town";$googleImages = implode(" ", file($url));preg_match_all("/(((a-zA-Z0-9-]*\.){1,})[a-zA-Z0-9\.\/_%&-~{1,}\.(jpg|JPG|gif|GIF))/", $googleImages, $imageArray);print_r($imageArray);?>[/code]but if i try to loop it to produce image urls for different towns it just prints 'array' for each town.[code]<?phpforeach($uniqueTown as $townImage) {$url = "http://images.google.co.uk/images?q=$townImage";$googleImages = implode(" ", file($url));preg_match_all("/(((a-zA-Z0-9-]*\.){1,})[a-zA-Z0-9\.\/_%&-~{1,}\.(jpg|JPG|gif|GIF))/", $googleImages, $imageArray);print_r($imageArray);}?>[/code]i know this is probably something really stupid but its got me stuck, could anyone help me out?Cheers, little milly. Quote Link to comment Share on other sites More sharing options...
milly Posted August 3, 2006 Author Share Posted August 3, 2006 any suggestions anyone? Quote Link to comment Share on other sites More sharing options...
SammyP Posted August 3, 2006 Share Posted August 3, 2006 I don't know everything about the stuff you are trying to do, but if you created a function to which you passed the town name, and had it return the array of image names, then it would really have to work the same whether you ran it one time or many.I wonder if preg_match_all does something unusual if the third parameter already has values in it. I suspect that might be your problem, but I haven't checked the help files for you.Does that help?Sam. Quote Link to comment Share on other sites More sharing options...
SharkBait Posted August 3, 2006 Share Posted August 3, 2006 If your loop is printing out the word 'array' each time. Then the array has an array inside of it.Check with print_f($uniqueTown) or even print_f($townImage) I guess :)Then if it is a multi-dimenision array, then just use nested loops. Quote Link to comment Share on other sites More sharing options...
milly Posted August 3, 2006 Author Share Posted August 3, 2006 i have tried...[code]oreach($uniqueTown as $townImage) {$url = "http://images.google.co.uk/images?q=$townImage";$googleImages = implode(" ", file($url));foreach($googleImage as $google) {preg_match_all("/(((a-zA-Z0-9-]*\.){1,})[a-zA-Z0-9\.\/_%&-~{1,}\.(jpg|JPG|gif|GIF))/", $google, $imageArray);foreach($imageArray as $image) {echo $image;}}}[/code]but this doesn't work either as returns nothing... can anyone see where i'm going wrong, please. Quote Link to comment Share on other sites More sharing options...
milly Posted August 4, 2006 Author Share Posted August 4, 2006 anymore more suggestions anyone... i'm really suck....:( Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.