【发布时间】:2016-02-10 02:43:56
【问题描述】:
我有一个页面,它会自动从 MySQL 数据库中检索两个随机条目,并在每次刷新页面时要求用户比较它们。如何自动将这两个字符串转换为第一个谷歌图像结果?这是我目前所拥有的:
<?php //I retrieve the names and group names here//
$firstpersonaName = (string) $row["personaName"];
$firstpersonaGroupName = (string) $row["groupName"];
$firstpersonaGroupNameForGoogle = preg_split('( )', $firstpersonaGroupName);
?> //then convert any group names containing spaces into arrays here//
<?php //then here I build the query that displays a google image page//
$newname = '';
foreach ($firstpersonaGroupNameForGoogle as $firstpersonaPartofGroupName) {
$newname = $firstpersonaPartofGroupName . '+';
}
$newname = rtrim($newname, "+");
echo "https://www.google.com/search?q=" . $firstpersonaName . "+" . $newname . '&tbm=isch';
?>
这给了我类似的东西:https://www.google.com/search?q=charlie+always+sunny&tbm=isch
那么我如何获取该链接并将其转换为第一张图片的链接?或者真的是第一对夫妇中的任何一个。 (在这种情况下:http://cdn3.denofgeek.us/sites/denofgeekus/files/sunny_0.jpg)
【问题讨论】:
标签: javascript php jquery google-image-search