Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
获取PHP中给定单词的图像的url_Php_Search - Fatal编程技术网

获取PHP中给定单词的图像的url

获取PHP中给定单词的图像的url,php,search,Php,Search,我正在开发一个程序,其背景图像将随着twitter的热门话题而改变。所以我有一个函数可以返回一个单词(首先是twitter上的TT),然后我需要另一个函数,它可以给我一个与该单词相关的图像url,比如谷歌图像搜索或flickr 你知道怎么做吗?或者更好,你有一个php脚本吗 总而言之:是否有一个功能可以进行谷歌图片或flickr搜索,并为单词返回相应的图片url请原谅我发布了一个答案,但我还没有50%的声誉,因此我不能留下评论 你没有说你在哪里得到你的图像 如果它们存储在本地,那么应该很简单,除

我正在开发一个程序,其背景图像将随着twitter的热门话题而改变。所以我有一个函数可以返回一个单词(首先是twitter上的TT),然后我需要另一个函数,它可以给我一个与该单词相关的图像url,比如谷歌图像搜索或flickr

你知道怎么做吗?或者更好,你有一个php脚本吗


总而言之:是否有一个功能可以进行谷歌图片或flickr搜索,并为单词返回相应的图片url

请原谅我发布了一个答案,但我还没有50%的声誉,因此我不能留下评论

你没有说你在哪里得到你的图像

如果它们存储在本地,那么应该很简单,除非您需要大量的图像,并且必须接受您仍然可能找不到匹配的图像

如果没有,你可以从谷歌图片中抓取第一张图片。注意可能存在的版权问题;您可能希望在许可证下找到一个充满图像的站点

在任何情况下,正如@zneak所说,如果你使用一个单词,你通常会得到令人惊讶的结果。

允许你搜索图像:,但我不确定你是否可以使用PHP解析结果。您当然可以解析返回的数据,提取图像URL作为背景应用。还有一个值得尝试的方法

有一个PHP,显示如何使用PHP调用搜索

下面是查找“蝙蝠侠”图像搜索结果的代码:

$word=“蝙蝠侠”;
$manual\u referer='1http://example.com/';
//有关如何修改搜索,请参见参考
// http://code.google.com/apis/ajaxsearch/documentation/reference.html
$args=数组(
“v”=>“1.0”,
'q'=>$word,
'as_filetype'=>'jpg',
'imgsz'=>'medium',//图像大小
'safe'=>'active',//图像“safeness”
'as_filetype'=>'jpg',
);
$url=”http://ajax.googleapis.com/ajax/services/search/images?";
foreach($args作为$key=>$val){
$url.=$key.'='.rawurlencode($val)。'&';
}
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,$URL);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_REFERER,$manual_REFERER);
$body=curl\u exec($ch);
卷曲关闭($ch);
$json=json_decode($body,true);
$results=$json['responseData']['results'];
foreach($results作为$result){
打印“”;
}
以下是原始返回的json解码时的样子:

Array
(
    [responseData] => Array
        (
            [results] => Array
                (
                    [0] => Array
                        (
                            [GsearchResultClass] => GimageSearch
                            [width] => 240
                            [height] => 338
                            [imageId] => k8FYqFKsdhvu3M:
                            [tbWidth] => 84
                            [tbHeight] => 119
                            [unescapedUrl] => http://lizilla.files.wordpress.com/2009/08/batman.jpg
                            [url] => http://lizilla.files.wordpress.com/2009/08/batman.jpg
                            [visibleUrl] => lizilla.wordpress.com
                            [title] => Superhero's, Animation, Comics, And Interesting Movies. « Lizilla
                            [titleNoFormatting] => Superhero's, Animation, Comics, And Interesting Movies. « Lizilla
                            [originalContextUrl] => http://lizilla.wordpress.com/2009/08/26/superheros-animation-comics-and-interesting-movies/
                            [content] => Dunanununanuna <b>BATMAN</b>!
                            [contentNoFormatting] => Dunanununanuna BATMAN!
                            [tbUrl] => http://images.google.com/images?q=tbn:k8FYqFKsdhvu3M::lizilla.files.wordpress.com/2009/08/batman.jpg
                        )

                    [1] => Array
                        (
                            [GsearchResultClass] => GimageSearch
                            [width] => 307
                            [height] => 290
                            [imageId] => faxJ90Dbo1TW1M:
                            [tbWidth] => 117
                            [tbHeight] => 111
                            [unescapedUrl] => http://www.solarnavigator.net/films_movies_actors/film_images/batman_michael_keaton_jack_nocholson_joker_marvel_comics.jpg
                            [url] => http://www.solarnavigator.net/films_movies_actors/film_images/batman_michael_keaton_jack_nocholson_joker_marvel_comics.jpg
                            [visibleUrl] => www.solarnavigator.net
                            [title] => <b>BATMAN</b> THE MOVIE
                            [titleNoFormatting] => BATMAN THE MOVIE
                            [originalContextUrl] => http://www.solarnavigator.net/films_movies_actors/batman.htm
                            [content] => <b>Batman</b> and the Joker in the
                            [contentNoFormatting] => Batman and the Joker in the
                            [tbUrl] => http://images.google.com/images?q=tbn:faxJ90Dbo1TW1M::www.solarnavigator.net/films_movies_actors/film_images/batman_michael_keaton_jack_nocholson_joker_marvel_comics.jpg
                        )

                    [2] => Array
                        (
                            [GsearchResultClass] => GimageSearch
                            [width] => 300
                            [height] => 300
                            [imageId] => nDWzhPnraNi_gM:
                            [tbWidth] => 116
                            [tbHeight] => 116
                            [unescapedUrl] => http://i192.photobucket.com/albums/z167/Great_WhiteSnark/batman_bale-1.jpg
                            [url] => http://i192.photobucket.com/albums/z167/Great_WhiteSnark/batman_bale-1.jpg
                            [visibleUrl] => www.coolchaser.com
                            [title] => <b>batman</b> MySpace graphics and comments
                            [titleNoFormatting] => batman MySpace graphics and comments
                            [originalContextUrl] => http://www.coolchaser.com/graphics/tag/batman
                            [content] => All Graphics » <b>batman</b>
                            [contentNoFormatting] => All Graphics » batman
                            [tbUrl] => http://images.google.com/images?q=tbn:nDWzhPnraNi_gM::i192.photobucket.com/albums/z167/Great_WhiteSnark/batman_bale-1.jpg
                        )

                    [3] => Array
                        (
                            [GsearchResultClass] => GimageSearch
                            [width] => 250
                            [height] => 302
                            [imageId] => W9EAV1DUDesHuM:
                            [tbWidth] => 96
                            [tbHeight] => 116
                            [unescapedUrl] => http://upload.wikimedia.org/wikipedia/en/thumb/f/f6/New_Batman_Adventures_cast.jpg/250px-New_Batman_Adventures_cast.jpg
                            [url] => http://upload.wikimedia.org/wikipedia/en/thumb/f/f6/New_Batman_Adventures_cast.jpg/250px-New_Batman_Adventures_cast.jpg
                            [visibleUrl] => en.wikipedia.org
                            [title] => The New <b>Batman</b> Adventures - Wikipedia, the free encyclopedia
                            [titleNoFormatting] => The New Batman Adventures - Wikipedia, the free encyclopedia
                            [originalContextUrl] => http://en.wikipedia.org/wiki/The_New_Batman_Adventures
                            [content] => The New <b>Batman</b> Adventures
                            [contentNoFormatting] => The New Batman Adventures
                            [tbUrl] => http://images.google.com/images?q=tbn:W9EAV1DUDesHuM::upload.wikimedia.org/wikipedia/en/thumb/f/f6/New_Batman_Adventures_cast.jpg/250px-New_Batman_Adventures_cast.jpg
                        )

                )

            [cursor] => Array
                (
                    [pages] => Array
                        (
                            [0] => Array
                                (
                                    [start] => 0
                                    [label] => 1
                                )

                            [1] => Array
                                (
                                    [start] => 4
                                    [label] => 2
                                )

                            [2] => Array
                                (
                                    [start] => 8
                                    [label] => 3
                                )

                            [3] => Array
                                (
                                    [start] => 12
                                    [label] => 4
                                )

                            [4] => Array
                                (
                                    [start] => 16
                                    [label] => 5
                                )

                            [5] => Array
                                (
                                    [start] => 20
                                    [label] => 6
                                )

                            [6] => Array
                                (
                                    [start] => 24
                                    [label] => 7
                                )

                            [7] => Array
                                (
                                    [start] => 28
                                    [label] => 8
                                )

                        )

                    [estimatedResultCount] => 3050000
                    [currentPageIndex] => 0
                    [moreResultsUrl] => http://www.google.com/images?oe=utf8&ie=utf8&source=uds&start=0&safe=active&imgsz=medium&as_filetype=jpg&hl=en&q=batman
                )

        )

    [responseDetails] => 
    [responseStatus] => 200
)
数组
(
[responseData]=>阵列
(
[结果]=>数组
(
[0]=>阵列
(
[GsearchResultClass]=>GimageSearch
[宽度]=>240
[高度]=>338
[imageId]=>k8FYqFKsdhvu3M:
[tbWidth]=>84
[tbHeight]=>119
[unescapedUrl]=>http://lizilla.files.wordpress.com/2009/08/batman.jpg
[网址]=>http://lizilla.files.wordpress.com/2009/08/batman.jpg
[visibleUrl]=>lizilla.wordpress.com
[标题]=>超级英雄、动画、漫画和有趣的电影
[标题信息]=>超级英雄、动画、漫画和有趣的电影。Lizilla
[原始上下文]=>http://lizilla.wordpress.com/2009/08/26/superheros-animation-comics-and-interesting-movies/
[内容]=>Dunnunna蝙蝠侠!
[contentNoFormatting]=>Dunnunna蝙蝠侠!
[tbUrl]=>http://images.google.com/images?q=tbn:k8FYqFKsdhvu3M::lizilla.files.wordpress.com/2009/08/batman.jpg
)
[1] =>阵列
(
[GsearchResultClass]=>GimageSearch
[宽度]=>307
[高度]=>290
[imageId]=>faxJ90Dbo1TW1M:
[tbWidth]=>117
[tbHeight]=>111
[unescapedUrl]=>http://www.solarnavigator.net/films_movies_actors/film_images/batman_michael_keaton_jack_nocholson_joker_marvel_comics.jpg
[网址]=>http://www.solarnavigator.net/films_movies_actors/film_images/batman_michael_keaton_jack_nocholson_joker_marvel_comics.jpg
[visibleUrl]=>www.solarnavigator.net
[标题]=>蝙蝠侠电影
[标题信息]=>蝙蝠侠电影
[原始上下文]=>http://www.solarnavigator.net/films_movies_actors/batman.htm
[内容]=>游戏中的蝙蝠侠和小丑
[contentNoFormatting]=>游戏中的蝙蝠侠和小丑
[tbUrl]=>http://images.google.com/images?q=tbn:faxJ90Dbo1TW1M::www.solarnavigator.net/films_movies_actors/film_images/batman_michael_keaton_jack_nocholson_joker_marvel_comics.jpg
)
[2] =>阵列
(
[GsearchResultClass]=>GimageSearch
[宽度]=>300
[高度]=>300
[imageId]=>nDWzhPnraNi\U gM:
[tbWidth]=>116
[tbHeight]=>116
[unescapedUrl]=>http://i192.photobucket.com/albums/z167/Great_WhiteSnark/batman_bale-1.jpg
[网址]=>http://i192.photobucket.com/albums/z167/Great_WhiteSnark/batman_bale-1.jpg
[visibleUrl]=>www.coolchaser.com
[标题]=>蝙蝠侠MyS
Array
(
    [responseData] => Array
        (
            [results] => Array
                (
                    [0] => Array
                        (
                            [GsearchResultClass] => GimageSearch
                            [width] => 240
                            [height] => 338
                            [imageId] => k8FYqFKsdhvu3M:
                            [tbWidth] => 84
                            [tbHeight] => 119
                            [unescapedUrl] => http://lizilla.files.wordpress.com/2009/08/batman.jpg
                            [url] => http://lizilla.files.wordpress.com/2009/08/batman.jpg
                            [visibleUrl] => lizilla.wordpress.com
                            [title] => Superhero&#39;s, Animation, Comics, And Interesting Movies. « Lizilla
                            [titleNoFormatting] => Superhero&#39;s, Animation, Comics, And Interesting Movies. « Lizilla
                            [originalContextUrl] => http://lizilla.wordpress.com/2009/08/26/superheros-animation-comics-and-interesting-movies/
                            [content] => Dunanununanuna <b>BATMAN</b>!
                            [contentNoFormatting] => Dunanununanuna BATMAN!
                            [tbUrl] => http://images.google.com/images?q=tbn:k8FYqFKsdhvu3M::lizilla.files.wordpress.com/2009/08/batman.jpg
                        )

                    [1] => Array
                        (
                            [GsearchResultClass] => GimageSearch
                            [width] => 307
                            [height] => 290
                            [imageId] => faxJ90Dbo1TW1M:
                            [tbWidth] => 117
                            [tbHeight] => 111
                            [unescapedUrl] => http://www.solarnavigator.net/films_movies_actors/film_images/batman_michael_keaton_jack_nocholson_joker_marvel_comics.jpg
                            [url] => http://www.solarnavigator.net/films_movies_actors/film_images/batman_michael_keaton_jack_nocholson_joker_marvel_comics.jpg
                            [visibleUrl] => www.solarnavigator.net
                            [title] => <b>BATMAN</b> THE MOVIE
                            [titleNoFormatting] => BATMAN THE MOVIE
                            [originalContextUrl] => http://www.solarnavigator.net/films_movies_actors/batman.htm
                            [content] => <b>Batman</b> and the Joker in the
                            [contentNoFormatting] => Batman and the Joker in the
                            [tbUrl] => http://images.google.com/images?q=tbn:faxJ90Dbo1TW1M::www.solarnavigator.net/films_movies_actors/film_images/batman_michael_keaton_jack_nocholson_joker_marvel_comics.jpg
                        )

                    [2] => Array
                        (
                            [GsearchResultClass] => GimageSearch
                            [width] => 300
                            [height] => 300
                            [imageId] => nDWzhPnraNi_gM:
                            [tbWidth] => 116
                            [tbHeight] => 116
                            [unescapedUrl] => http://i192.photobucket.com/albums/z167/Great_WhiteSnark/batman_bale-1.jpg
                            [url] => http://i192.photobucket.com/albums/z167/Great_WhiteSnark/batman_bale-1.jpg
                            [visibleUrl] => www.coolchaser.com
                            [title] => <b>batman</b> MySpace graphics and comments
                            [titleNoFormatting] => batman MySpace graphics and comments
                            [originalContextUrl] => http://www.coolchaser.com/graphics/tag/batman
                            [content] => All Graphics » <b>batman</b>
                            [contentNoFormatting] => All Graphics » batman
                            [tbUrl] => http://images.google.com/images?q=tbn:nDWzhPnraNi_gM::i192.photobucket.com/albums/z167/Great_WhiteSnark/batman_bale-1.jpg
                        )

                    [3] => Array
                        (
                            [GsearchResultClass] => GimageSearch
                            [width] => 250
                            [height] => 302
                            [imageId] => W9EAV1DUDesHuM:
                            [tbWidth] => 96
                            [tbHeight] => 116
                            [unescapedUrl] => http://upload.wikimedia.org/wikipedia/en/thumb/f/f6/New_Batman_Adventures_cast.jpg/250px-New_Batman_Adventures_cast.jpg
                            [url] => http://upload.wikimedia.org/wikipedia/en/thumb/f/f6/New_Batman_Adventures_cast.jpg/250px-New_Batman_Adventures_cast.jpg
                            [visibleUrl] => en.wikipedia.org
                            [title] => The New <b>Batman</b> Adventures - Wikipedia, the free encyclopedia
                            [titleNoFormatting] => The New Batman Adventures - Wikipedia, the free encyclopedia
                            [originalContextUrl] => http://en.wikipedia.org/wiki/The_New_Batman_Adventures
                            [content] => The New <b>Batman</b> Adventures
                            [contentNoFormatting] => The New Batman Adventures
                            [tbUrl] => http://images.google.com/images?q=tbn:W9EAV1DUDesHuM::upload.wikimedia.org/wikipedia/en/thumb/f/f6/New_Batman_Adventures_cast.jpg/250px-New_Batman_Adventures_cast.jpg
                        )

                )

            [cursor] => Array
                (
                    [pages] => Array
                        (
                            [0] => Array
                                (
                                    [start] => 0
                                    [label] => 1
                                )

                            [1] => Array
                                (
                                    [start] => 4
                                    [label] => 2
                                )

                            [2] => Array
                                (
                                    [start] => 8
                                    [label] => 3
                                )

                            [3] => Array
                                (
                                    [start] => 12
                                    [label] => 4
                                )

                            [4] => Array
                                (
                                    [start] => 16
                                    [label] => 5
                                )

                            [5] => Array
                                (
                                    [start] => 20
                                    [label] => 6
                                )

                            [6] => Array
                                (
                                    [start] => 24
                                    [label] => 7
                                )

                            [7] => Array
                                (
                                    [start] => 28
                                    [label] => 8
                                )

                        )

                    [estimatedResultCount] => 3050000
                    [currentPageIndex] => 0
                    [moreResultsUrl] => http://www.google.com/images?oe=utf8&ie=utf8&source=uds&start=0&safe=active&imgsz=medium&as_filetype=jpg&hl=en&q=batman
                )

        )

    [responseDetails] => 
    [responseStatus] => 200
)