Jump to content


Photo

Help with printing arrays of image url's


  • Please log in to reply
5 replies to this topic

#1 milly

milly
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 03 August 2006 - 09:23 AM

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.

<?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);

?>

but if i try to loop it to produce image urls for different towns it just prints 'array' for each town.

<?php

foreach($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);
}
?>

i know this is probably something really stupid but its got me stuck, could anyone help me out?

Cheers, little milly.

#2 milly

milly
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 03 August 2006 - 01:02 PM

any suggestions anyone?

#3 SammyP

SammyP
  • Members
  • PipPipPip
  • Advanced Member
  • 58 posts
  • LocationLondon

Posted 03 August 2006 - 01:09 PM

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.
If this has solved your problem, a quick 'Thanks' is appreciated, but marking the thread as 'Solved' is better - it saves a lot of time.

Sam.

#4 SharkBait

SharkBait
  • Members
  • PipPipPip
  • Advanced Member
  • 845 posts
  • LocationMetro Vancouver, BC

Posted 03 August 2006 - 03:07 PM

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.

#5 milly

milly
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 03 August 2006 - 04:15 PM

i have tried...
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;
}
}
}

but this doesn't work either as returns nothing... can anyone see where i'm going wrong, please.

#6 milly

milly
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 04 August 2006 - 09:21 AM

anymore more suggestions anyone... i'm really suck....:(




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users