Help with a script

Help with a script

am 06.08.2007 10:34:17 von Amy

I 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.


foreach ($suggest_items as $key => $value) {
echo "";
}
echo "
http://www.google.com/search?hl=en&btnG=Google+Search&q=$key '
target='_blank'>$key
" . trim($value) .
"
http://www.mydomain.com/suggest.php?keyword=$key' target='_self'>Get
Suggestion
";
}


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">



Google Suggest Keyword Tool










cellspacing="0" >

width="100%" align="center">


type="text" size="35" name="keyword" />


if ($show_suggest) {
?>

foreach ($suggest_items as $key => $value) {
echo "";
}
echo "
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);}?>

Re: Help with a script

am 06.08.2007 10:38:09 von luiheidsgoeroe

On Mon, 06 Aug 2007 10:34:17 +0200, *69 wrote:

> I downloaded the 2 below PHP scripts. There are two individual script=
s,
> 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.
>
>


> > foreach ($suggest_items as $key =3D> $value) {
> echo "";
> }
> echo "

href=3D' ?

> http://www.google.com/search?hl=3Den&btnG=3DGoogle+Search&q= 3D$key'
> target=3D'_blank'>$key
" . trim($value) =
..
> "

href=3D' ?

> http://www.mydomain.com/suggest.php?keyword=3D$key' target=3D'_self'>G=
et
> Suggestion
";
> }
>
>
> Would someone be able to advise what is wrong?

Well, validate the HTML.
-- =

Rik Wasmus

Re: Help with a script

am 06.08.2007 10:57:51 von Amy

Thank you

"Rik" wrote in message
news:op.twmp9vvzqnv3q9@metallium...
On Mon, 06 Aug 2007 10:34:17 +0200, *69 wrote:

> I 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.
>
>


> > foreach ($suggest_items as $key => $value) {
> echo "";
> }
> echo "

href=' ?

> http://www.google.com/search?hl=en&btnG=Google+Search&q=$key '
> target='_blank'>$key
" . trim($value) .
> "

href=' ?

> http://www.mydomain.com/suggest.php?keyword=$key' target='_self'>Get
> Suggestion
";
> }
>
>
> Would someone be able to advise what is wrong?

Well, validate the HTML.
--
Rik Wasmus