Mercurial > hg > ywww
comparison examples/search/index.php @ 6:077b0a0a3e6d
remaining originals according to dependency walk
| author | Robert Boland <robert@markup.co.uk> |
|---|---|
| date | Thu, 16 Feb 2017 22:29:02 +0000 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 5:55445b456ad0 | 6:077b0a0a3e6d |
|---|---|
| 1 <html> | |
| 2 <head> | |
| 3 <title>PHP Sample Search Engine</title> | |
| 4 </head> | |
| 5 <link rel="stylesheet" type="text/css" href="style.css"> | |
| 6 <body OnLoad="document.searchForm.q.focus();"> | |
| 7 <div id="search"> | |
| 8 <form name="searchForm" action="index.php"> | |
| 9 | |
| 10 <?PHP | |
| 11 | |
| 12 $query = urlencode($_GET ['q']); // Get query term | |
| 13 $count = urlencode($_GET ['c']); // Get result count | |
| 14 | |
| 15 if($count < 1) | |
| 16 $count = 10; //do not allow zero or negative search results | |
| 17 | |
| 18 if($query == "") | |
| 19 $startText = "Enter your search here!"; | |
| 20 else | |
| 21 $startText = urldecode($query); | |
| 22 | |
| 23 echo "<input class=\"largeText\" type=\"text\" name=\"q\" size=\"50\" value=\"$startText\">"; | |
| 24 echo "<input class=\"submitButton\" type=\"submit\" value=\"Search\"/>"; | |
| 25 echo "<label for=\"c\">Number of Results:</label><input type=\"text\" name=\"c\" size=\"3\" value=\"$count\">"; | |
| 26 echo "</form>"; | |
| 27 | |
| 28 if($query !="") | |
| 29 { | |
| 30 include("resultsSet.php"); | |
| 31 | |
| 32 //-----------------------------SPELL CHECK----------------------------- | |
| 33 $spell = new resultsSet('spelling',$count); | |
| 34 $xml = $spell->getXMLResults($query); | |
| 35 foreach ($xml->resultset_spell->result as $result) { | |
| 36 echo '<h3>Did you mean? <a href="index.php?q='.$result->suggestion.'">'.$result->suggestion.'</a></h3><br/>'; | |
| 37 } | |
| 38 //Note, Yahoo spellcheck doesn't seem particularly good, but one example it detects is 'Seach' which it suggests as 'Search' | |
| 39 | |
| 40 echo "</div>"; | |
| 41 | |
| 42 //-----------------------------WEB RESULTS----------------------------- | |
| 43 $web = new resultsSet('web',$count); | |
| 44 $xml = $web->getXMLResults($query); | |
| 45 echo "<div id=\"left\">"; | |
| 46 echo "<h2>Web:</h2><br/>"; | |
| 47 foreach ($xml->resultset_web->result as $result) { | |
| 48 echo '<a href="'.$result->clickurl.'">'.$result->title.'</a>'; | |
| 49 echo '<p>'.$result->abstract.'</p>'; | |
| 50 echo '<a href="'.$result->dispurl.'">'.$result->dispurl.'</a><hr />'; | |
| 51 } | |
| 52 echo "</div> "; | |
| 53 | |
| 54 //-----------------------------IMAGE RESULTS----------------------------- | |
| 55 $images = new resultsSet('images',$count); | |
| 56 $xml = $images->getXMLResults($query); | |
| 57 echo "<div id=\"content\">"; | |
| 58 echo "<h2>Images:</h2><br/>"; | |
| 59 foreach ($xml->resultset_images->result as $result) { | |
| 60 echo '<a href="'.$result->clickurl.'"><img src='.$result->clickurl.' alt="'.$result->filename.'"></a>'; | |
| 61 } | |
| 62 echo "</div> "; | |
| 63 | |
| 64 //-----------------------------NEWS RESULTS----------------------------- | |
| 65 $news = new resultsSet('news',$count); | |
| 66 $xml = $news->getXMLResults($query); | |
| 67 echo "<div id=\"right\">"; | |
| 68 echo "<h2>News:</h2><br/>"; | |
| 69 foreach ($xml->resultset_news->result as $result) { | |
| 70 echo '<a href="'.$result->clickurl.'">'.$result->title.'</a>'; | |
| 71 echo '<p>'.$result->abstract.'</p>'; | |
| 72 echo '<p>Date: '.$result->date .'</p>'; | |
| 73 echo 'Source: <a href="'.$result->sourceurl.'">'.$result->sourceurl.'</a><hr />'; | |
| 74 } | |
| 75 echo "</div> "; | |
| 76 } | |
| 77 ?> | |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | |
| 83 |
