当在文本框中键入值时,如何调用php函数?

时间:2015-08-19 09:27:42

标签: javascript php google-search completion

我想使用Firefox的建议进行自动完成。键入关键字时是否可以调用php函数?有没有更好的方法呢?

 public function stealSearchGoogle(){ 

    $lang  = 'fr';
    $query = 'developeur';
    $url   = 'http://suggestqueries.google.com/complete/search?output=firefox&client=firefox&hl=' . $lang . '&q=' . urlencode($query);

    $ch    = curl_init($url);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
    curl_setopt($ch, CURLOPT_TIMEOUT, 10);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.0; rv:2.0.1) Gecko/20100101 Firefox/4.0.1");
    $data = curl_exec($ch);
    curl_close($ch);

    $suggestions = json_decode($data, true);

    if ($suggestions) {
        //echo 'suggestions: ';
        foreach ($suggestions as $value) {
            return($value);
        }

    }
}

0 个答案:

没有答案