Page 1 of 1

Unfinished Search Script !?!

Posted: Wed Oct 22, 2003 5:49 am
by mudkicker
Hi there,
Below is a basic search script of mine which i want to make more useful.
I must to ignore html tags and script codes (JS and PHP).
I need to highlight the search term in results...
Is there any idea how to do these? :?
Thanks,
Have a nice day!
greetings from turkey :wink:

Code: Select all

<?
// Opening directory & Reading the files...
$diary_directory = opendir(".");

while($filename = readdir($diary_directory))
{
if(!is_dir($filename))
{
if(/*eregi(".php",$filename) || */eregi(".html",$filename) || eregi(".htm",$filename))
 {	$fl[] = $filename; }
}
}
closedir($diary_directory);
// Matching?
$k=0;
for($i=0; $i<count($fl);$i++)
{
$file = file($fl[$i]);
$file = implode("",$file);
if(eregi($kriter,$file))
	{
	$sonuc[] = $fl[$i];
	$k++;
	}
}
// Displaying Results...
if($k==0) { echo "Hiç Sonuç yok"; }
else
{
 echo $k." Sonuc Bulundu:<br>";
 for($p=0;$p < count($sonuc); $p++)
 	{
	echo "<li><a href='$sonuc[$p]'>".$sonuc[$p]."</a><br>";
	}
}
?>
?>

Posted: Wed Oct 22, 2003 10:15 am
by murph
This is what i do, i break up all the words by removing the spaces and searching for each word. Then i use this code to highlight

Code: Select all

$broken = explode(" ",$search);
            foreach($broken as $key=>$value)
            {
            $result  = preg_replace("/({$value})/i","<b><font color="#D92727">\\1</font></b>",$result);
            }

Posted: Wed Oct 22, 2003 3:54 pm
by mudkicker
where should i add this code part? i don't have any possibility to include it in every page.

Posted: Thu Oct 23, 2003 4:18 am
by mudkicker

Code: Select all

<?php
// Checking if search variable is set or displays the form (echoes error?)...
if(!isset($kriter))
{
?>
<center>
<form action="<?=$PHP_SELF?>" method="post">
<input type="text" name="kriter" alt="Aranacak Kelimeyi Buraya Yaz&#305;n"><br>
<input type="submit" name="ara" value="Ara!">
</form>
</center>
<?
exit;
}
// Opening directory & Reading the files...
$diary_directory = opendir(".");

while($filename = readdir($diary_directory))
{
if(!is_dir($filename))
{
if(/*eregi(".php",$filename) || */eregi(".html",$filename) || eregi(".htm",$filename))
 {	$fl[] = $filename; }
}
}
closedir($diary_directory);
// Matching?
$tt = explode(" ",$kriter);
//$tt[]=$kriter;
for($i=0; $i<count($fl);$i++)
{
$file = file($fl[$i]);
$file = implode("",$file);
foreach($tt as $key=>$ttval)
{
if(eregi($ttval,$file))
	{
	$sonuc[] = $fl[$i];
	}
}
}
if($sonuc)
{
$sonucunique = array_unique($sonuc);
$k = count($sonucunique);
// Displaying Results...
echo $k." Sonuç Bulundu:<br>";
 for($p=0;$p < $k; $p++)
 	{
	echo "<li><a href='$sonuc[$p]'>".$sonucunique[$p]."</a><br>";
	}
} else { echo "Hiç Sonuç yok"; }
?>
I wrote this and actually working nice for me but i still having problems by highlighting and ignoring html tags and other sh*t. I thought that I could to achieve this by searching only for parts between <body></body>,<title></title> tags? any ideas or any scripts for this???