How to do site search in a website? for example if we search a keyword in search box of the daniweb it will give the result from daniweb site only. like that i want to do in my website.
Do you want to build your own, or do you want to use Google Custom Search (looks like this is what DW is using) ?
The following is a PHP-script hich will search the folder it itself is placed in plus all subfolders:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Find</title> <link rel="stylesheet" href="lind.css" type="text/css"> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta name='description' content='' /> <meta name='keywords' content=''> </head> <body> <h2>Search the files</h2> <?php $dennefil=$_SERVER["PHP_SELF"]; if (isset($_REQUEST['handling'])){ $handling=$_REQUEST["handling"];} if (isset($_REQUEST['ordet'])){ $ordet=$_REQUEST["ordet"];} if ($ordet==""){ $ordet="xxx";} if (isset($_REQUEST['ordetb'])){ $ordetb=$_REQUEST["ordetb"];} //--------------- funktioner function find($mappe){ global $ordet, $ordet2, $ordetb, $ordetb2; //echo "<b>$mappe</b>"; $sti=opendir($mappe); while ($filnavnet=readdir($sti)){ $type=filetype($mappe."/".$filnavnet); if ($type=="file" && $filnavnet !="index.php" && $filnavnet !="tiny.php" && $filnavnet !=".htpasswd" && $filnavnet !=".htaccess" && $filnavnet !="find.php") { find2($mappe."/".$filnavnet); } elseif ($type=="dir" && $filnavnet !=".." && $filnavnet !="." && $filnavnet !="tiny_mce" && $filnavnet !="billeder") { find("$mappe/$filnavnet"); } } // while closedir($sti); } // ------------- slut på find() // find2() function find2($filnavnet) { global $ordet, $ordet2; $f=fopen($filnavnet,"r"); $teksten=fread($f, filesize($filnavnet)); fclose($f); $teksten=stristr($teksten,"<body"); $teksten=strip_tags($teksten,"<p>"); $teksten=explode("<",$teksten); for ($i=0; $i<count($teksten); $i++) { if ( (eregi($ordet,$teksten[$i]) OR eregi($ordet2,$teksten[$i])) ) { echo "<a href=\"$filnavnet\">$filnavnet</a>:"; $strengen=stristr($teksten[$i],">"); $strengen=substr($strengen,1,strlen($strengen)); $strengen=str_replace($ordet,"<span style='background:rgb(127,255,212)'>$ordet</span>",$strengen); $strengen=str_replace($ordet2,"<span style='background:rgb(0,220,255)'>$ordet2</span>",$strengen); echo $strengen.""; } } } // -------------------------slut på function // ------- søgeformularen echo <<<SLUT <form name='form' action="$dennefil" method="post"> Enter text: <input type="text" name="ordet"> <input type="submit" name=handling value="Find"> </form> <script language='JavaScript' type='text/javascript'> //<!-- document.form.ordet.focus() //--> </script> SLUT; // ----------------- søg i teksterne if ($handling== "Find") { if (isset($ordet)){ //$ordet=strip_tags($ordet); echo "<b>Søgning på: \"$ordet\""; $ordet2=htmlentities($ordet); } echo "</b>"; $mappe="."; find($mappe); } ?> </body> </html>
It was originally made in Danish, but I think that will hardly be a problem.
Google Custom Search this is what i want... Pritaeas, thank you so much for the link.