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!
<?
// Checking if search variable is set or displays the form (echoes error?)...
if(!isset($kriter))
{
?>
<center>
<h5><span class="style2">PHP Arama Scripti</span></h5>
<span class="style1">
<form action="<?=$PHP_SELF?>" method="post">
Aranacak Kelime: <input name="kriter" type="text" class="style1" alt="Aranacak Kelimeyi Buraya Yazin">
<input name="ara" type="submit" class="style1" value="Ara!">
</form>
<b>NOT</b>: Eger full text aramak istiyorsaniz arayacagin terimi <b>""</b> isareti ile belirtin.</span>
</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);
// Checking if it's full phrase or what?
$ilkk = substr($kriter,1,1);
$sonk = substr($kriter,-1);
if($ilkk == """ && $sonk == """)
{ $tt[] = substr($kriter,2,-2); }
else
{ $tt = explode(" ",$kriter); }
// Matching?
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 "<p class='style1'>".$k." Sonuç Bulundu:</p>";
for($p=0;$p < $k; $p++)
{
echo "<li><a href='$sonuc[$p]' class='style1'>".$sonucunique[$p]."</a><br>";
}
} else { echo "<span class='style1'>Aranan Kelime Bulunamadý!</span>"; }
?>
This is my search script. as i open all the files in the directory with the file() function. i have to ignore php tags and search only the text between for example <title></title> and <body></body> tags. How can I do this? Is anyone have an idea or a function to do this?
Thanks!!!
function safehtml($str) {
//nuke script and header tags and anything inbetween
$str = preg_replace("'<script[^>]*?>.*?</script>'si", "", $str);
$str = preg_replace("'<head[^>]*?>.*?</head>'si", "", $str);
//listed of tags that will not be striped but whose attributes will be
$allowed = "br|b|i|p|u|a|block|pre|center|hr|body"; // added body - JAM
//start nuking those suckers. don you just love MS Word's HTML?
$str = preg_replace("/<((?!\/?($allowed)\b)[^>]*>)/xis", "", $str);
$str = preg_replace("/<($allowed).*?>/i", "<\\1>", $str);
return $str;
}
Tweaking needed. preg/ereg functions is worth looking into imho.