开发者

Google Image Result with PHP

开发者 https://www.devze.com 2023-03-31 03:23 出处:网络
I\'m building a PHP web app which requires a dynamic list of images, based on a MySQL database. For example, if the database consisted of \"house\", \"car\", and \"plane\", I\'d like to display three

I'm building a PHP web app which requires a dynamic list of images, based on a MySQL database. For example, if the database consisted of "house", "car", and "plane", I'd like to display three images of a house, a car, and a plane. I do not want t开发者_开发问答o store these images locally, because the database will be constantly changing. Instead, I'd like it to query Google Images using PHP and then generate an image URL that I can echo to HTML to display the image. Even better, if it could be customized with a random image index (so it won't use the first image every time), that would be even better.

Can anyone help? Thanks!


Google used to have an image search api (http://code.google.com/apis/imagesearch/) but that has been deprecated. If you need a reliable method I would not advise using anything that is deprecated but that is up to you and your application spec.

Another way would be to curl www.google.com/search?tbm=isch&q= and scrape the html that is returned. I believe that this is against Google's TOS so again use with caution.

I would suggest looking into other services than Google. Here is Bings api doc (http://msdn.microsoft.com/en-us/library/dd251072.aspx) as an example.

0

精彩评论

暂无评论...
验证码 换一张
取 消