Help with a script
am 06.08.2007 10:34:17 von AmyI downloaded the 2 below PHP scripts. There are two individual scripts,
listed below:
When you run suggest.php, and type in a keyword, it goes to google and
brings back a list of suggested words. These words should be hyperlinked so
that you can click them and it would bring back another list of words.
Problem is the "Get Suggestion" is not hyperlinked.
I'm assuming the code for that is in here somewhere.
}
Would someone be able to advise what is wrong?
Thank you
*************************************
suggest.php
*************************************
require("suggest_inc.php");
$suggest_items = array();
$show_suggest = false;
$keyword = "";
$no_suggest = false;
if (isset($_POST["keyword"])) {
$keyword = $_POST["keyword"];
} elseif (isset($_GET["keyword"])) {
$keyword = $_GET["keyword"];
}
if ($keyword != "") {
$suggest = new SuggestGetter();
$suggest_items = $suggest->GetSuggest($keyword);
if (count($suggest_items) > 0) {
$show_suggest = true;
} else {
$no_suggest = true;
}
}
?>
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
if ($show_suggest) {
?>
http://www.google.com/search?hl=en&btnG=Google+Search&q=$key ' target='_blank'>$key | " . trim($value) . " | target='_self'>Get Suggestion |
}
?>
*************************************
suggest_inc.php
*************************************
class SuggestGetter
{
//---------------------------------------------------------- ---------------- function GetSuggest($keyword) { $items = array(); $url = $this->buildSuggestUrl($keyword); $data = $this->getRawSuggest($url); if ($data) { $data = strstr($data, 'new Array('); if ($data === FALSE) return $items; $data = substr($data, strlen('new Array(')); $i = strpos($data, ')'); if ($i === FALSE) return $items; $tmp = substr($data, 0, $i - 1); $tmp = str_replace('"', "", $tmp); $keys = explode(",", $tmp); $data = strstr($data, 'new Array('); if ($data === FALSE) return $items; $data = substr($data, strlen('new Array(')); $i = strpos($data, ')'); if ($i === FALSE) return $items; $tmp = substr($data, 0, $i - 1); $values = explode('",', $tmp); $values = array_map("stripQuotes", $values); if (count($keys) == count($values)) { $items = $this->safeArrayCombine($keys, $values); } } return $items; } //---------------------------------------------------------- ---------------- function buildSuggestUrl($keyword) { return "http://www.google.com/complete/search?hl=en&js=true&qu=" .urlencode($keyword); } function getRawSuggest($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, FALSE); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); $data = curl_exec($ch); curl_close($ch); if (!($data === FALSE)) { return $data; } else { return false; } } function safeArrayCombine($a, $b) { if (count($a)!=count($b)) return FALSE; foreach($a as $key) list(,$c[$key])=each($b); return $c; }}function stripQuotes($item){ return str_replace('"', "", $item);}?>