Jump to content

Archived

This topic is now archived and is closed to further replies.

milly

Help with printing arrays of image url's

Recommended Posts

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]
<?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);
}
?>
[/code]

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

Cheers, little milly.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.