SEO Services
Home >>
Webmaster Forums >>
how do i add a searchbar to search my site?how do i add a searchbar to search my site?
the thin ice said: "how do i add a searchbr to search my site?
maybe a "if "word" then go"www.site.com/info.htm" type of thing, god knows"
Darren said: "You can script a small search engine box yourself (complicated), or you can search Google for small search boxes that will index you site.
Generally the free ones require a link back to the author's website."
<h1> said: "you want a simple if this word or phrase is searched then display this file. Here I previously made such an example. If you understand php then you will be able to easily implement this script.
[PHP]
// Lets make a "fake" search.
// If the searchstring is found in the multi-dimensional array then return
// the page url, title and description which is also stored in the multi-dimensional array
// The searchstring can be matched more than once.
// 2 stage script. 1st display form, 2nd display results
$searcharray = array(
array('home.html','Home','The homepage, this page contact menu and cotact details','home','contact'),
array('products.html','Products','All the products are shown in this page','products','caps','shirts','home'),
array('guestbook.html','The guestbook','sign out guestbook or just surf the current entires','guestbook'),
);
function displayform()
{
echo '
';
}
function searchresults($resultsarray,$word,$originalarray)
{
print "Searched phrase: $word
";
print "Search Results: (".(count($resultsarray)).") pages found.";
print "
Pages:
";
// display pages
for ($counter=0;$counter<(count($resultsarray));$counter++)
{
$temp = $resultsarray[$counter];
print "
".$originalarray[$temp][1]."Description: ".$originalarray[$temp][2]."
";
}
}
function search($whicharray,$word)
{
$numberarray = array();
$tempcount = 0;
foreach ($whicharray as $number => $data)
{
//print $number;
foreach ($data as $value)
{
//print $value;
if ((trim(strtolower($value)) == trim(strtolower($word))) && ($tempcount > 2))
{
array_push($numberarray, $number);
}
$tempcount ++;
}
$tempcount=0;
}
return $numberarray;
}
if (empty($stage)) $stage = 1;
switch ($stage)
{
case 1:
displayform();
break;
case 2:
$results = (search($searcharray,$searchstring));
//print $results[0];
//print $searcharray[$results][0];
if (!empty($results))
{
searchresults($results,$searchstring,$searcharray);
}
else print "No results found for ".$searchstring;
}
?>[/PHP]
goto [URL]http://www.exzibit.co.za/search.php[/URL] to view this specific script in action.
Search for 'products' and 'home' to view the script retrieving more than one entry.
peace
rich"
the thin ice said: "hey thanks, i reckon i can do something with that
also, i found this which was also pretty helpful
[url]http://www.perlfect.com/freescripts/search/[/url]"
<h1> said: "no probs
it was made for its simplicity..
peace"