Jump to content

Help with printing arrays of image url's


milly

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.