PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
mudkicker
Forum Contributor
Posts: 479 Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:
Post
by mudkicker » Wed Oct 22, 2003 5:49 am
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
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>";
}
}
?>
?>
murph
Forum Commoner
Posts: 29 Joined: Fri Oct 03, 2003 1:28 pm
Location: washington
Post
by murph » Wed Oct 22, 2003 10:15 am
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);
}
mudkicker
Forum Contributor
Posts: 479 Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:
Post
by mudkicker » Wed Oct 22, 2003 3:54 pm
where should i add this code part? i don't have any possibility to include it in every page.
mudkicker
Forum Contributor
Posts: 479 Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:
Post
by mudkicker » Thu Oct 23, 2003 4:18 am
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ı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???