Reply to Help with a script

Your name:

Reply:


Posted by *69 on 08/06/07 08:34

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.

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


Would someone be able to advise what is wrong?

Thank you



*************************************
suggest.php
*************************************


<?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;
}
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Google Suggest Keyword Tool</title>

</head>
<body>
<table width="480" height="121%" border="0" align="center" valign="middle">

<tr>
<td width="100%" height="242" align="center" valign="top"><br />
<table width="409" border="0" align="center" cellpadding="0"
cellspacing="0" >
<tr>
<td width="420" height="174" align="center" valign="top"><table
width="100%" align="center">
<tr>
<td height="26"><form><input value="<?php echo $keyword; ?>"
type="text" size="35" name="keyword" />
<input type="submit" value="Get Suggestion"/>
</form> </td>
</table>
<?php
if ($show_suggest) {
?>
<table align="center">
<?php
foreach ($suggest_items as $key => $value) {
echo "<tr><td class='details'><a
http://www.google.com/search?hl=en&btnG=Google+Search&q=$key'
target='_blank'>$key</a></td><td class='details'>" . trim($value) .
"</td><td class='details'><a http://www.domain.com/suggest.php?keyword=$key'
target='_self'>Get Suggestion</a</td></tr>";
}
echo "</table>";
}
?>
<br />
<br />
<br />
</table> </td>
</tr>
</table>
<br />
<br />

</table>
</body>
</html>

*************************************
suggest_inc.php
*************************************

<?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);}?>

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация