Page 1 of 1

How Can I ??? please help...

Posted: Tue Oct 28, 2003 3:38 am
by mudkicker
hi people i had to ask one more question.

Code: Select all

<?

// 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!!!

Posted: Tue Oct 28, 2003 7:03 am
by volka
you might find these functions useful:
http://php.net/strip_tags
http://php.net/fgetss

Posted: Tue Oct 28, 2003 7:09 pm
by mudkicker
thanks mate strip_tags could be useful but the 2nd paramter for it (allowable tags) how can i define the whole tags except body and text tags?

Posted: Tue Oct 28, 2003 7:29 pm
by JAM
Might this give you more ideas, taken from php.net usercomments:

Code: Select all

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.

Posted: Wed Oct 29, 2003 3:36 am
by mudkicker
thank you for your help! this is exactly what i wanted to, i think?!!?!?