0

我正在使用以下脚本从 Google Suggestions 中提取信息:

<?php
function getKeywordSuggestionsFromGoogle($keyword) {
    $keywords = array();
    $data = file_get_contents('http://suggestqueries.google.com/complete/search?output=firefox&client=firefox&hl=en-US&q='.urlencode($keyword));
    if (($data = json_decode($data, true)) !== null) {
        $keywords = $data[1];
    }

    return $keywords;
}

var_dump(getKeywordSuggestionsFromGoogle('business'));
?>

这是在浏览器中访问 PHP 文件时显示的内容:

array(10) { [0]=> string(14) "business cards" [1]=> string(22) "business letter format" [2]=> string(16) "business insider" [3]=> string(15) "business casual" [4]=> string(13) "business plan" [5]=> string(22) "business plan template" [6]=> string(13) "business week" [7]=> string(14) "business ideas" [8]=> string(17) "business for sale" [9]=> string(8) "business" } 

我需要弄清楚如何做两件事:

  1. 在我的网页上正确显示信息,使其看起来像这样:

    名片、商务信函格式等

  2. 我需要像这样链接到我的域的每个关键字:

    名片商务信函格式

任何帮助将不胜感激!谢谢!

4

1 回答 1

0

像这样试试......

<?php
function getKeywordSuggestionsFromGoogle($keyword) {
    $keywords = array();
    $data = file_get_contents('http://suggestqueries.google.com/complete/search?output=firefox&client=firefox&hl=en-US&q='.urlencode($keyword));

    if (($data = json_decode($data, true)) !== null) {
        $keywords = $data[1];
    }

    return $keywords;
}

$result = getKeywordSuggestionsFromGoogle('business');


foreach($result as $key => $r)

  {

     echo '<a href = "http://www.mysite.com/keywords/'. $r.'">'. $r .'</a>';

   }
 ?>

如果你想参考一些链接,你可以把它echo $r放在中间<a href="#"><?php echo $r ?></a>

于 2013-02-20T08:57:39.350 回答