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.

Recommended Answers

All 3 Replies

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">
<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=''>
<h2>Search the files</h2>

if (isset($_REQUEST['handling'])){
if (isset($_REQUEST['ordet'])){
if ($ordet==""){
if (isset($_REQUEST['ordetb'])){

//--------------- funktioner
function find($mappe){
global $ordet, $ordet2, $ordetb, $ordetb2;
//echo "<b>$mappe</b><br />";
while ($filnavnet=readdir($sti)){


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

// ------------- slut på find()

// find2()

function find2($filnavnet) {

global $ordet, $ordet2;

$teksten=fread($f, filesize($filnavnet));

for ($i=0; $i<count($teksten); $i++) {

if (
(eregi($ordet,$teksten[$i]) OR eregi($ordet2,$teksten[$i]))

echo "<br><a href=\"$filnavnet\">$filnavnet</a>:<br />";
$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."<br>";


} // -------------------------slut på function

// ------- søgeformularen

echo <<<SLUT
<form name='form' action="$dennefil" method="post">
Enter text: &nbsp;
<input type="text" name="ordet">
<input type="submit" name=handling value="Find">
<script language='JavaScript' type='text/javascript'>


// ----------------- søg i teksterne

if ($handling== "Find") {
if (isset($ordet)){
echo "<br><b>Søgning på: \"$ordet\"";

echo "</b><br><br>";



It was originally made in Danish, but I think that will hardly be a problem.

Do you want to build your own, or do you want to use Google Custom Search (looks like this is what DW is using) ?

Google Custom Search this is what i want... Pritaeas, thank you so much for the link.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.