How Can I ??? please help...

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

Post Reply
User avatar
mudkicker
Forum Contributor
Posts: 479
Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:

How Can I ??? please help...

Post 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!!!
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

you might find these functions useful:
http://php.net/strip_tags
http://php.net/fgetss
User avatar
mudkicker
Forum Contributor
Posts: 479
Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:

Post 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?
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post 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.
User avatar
mudkicker
Forum Contributor
Posts: 479
Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:

Post by mudkicker »

thank you for your help! this is exactly what i wanted to, i think?!!?!?
Post Reply