You have to do a while statement to get the files first, (can view one of those at http://www.php.net 's online documentation (search for: readdir function).) then try and get this.
how do I make a file where each line is part of an array.
basically so i can do something this:
$filtered = str_replace($foul, "", $fullabrv);
You have to do a while statement to get the files first, (can view one of those at http://www.php.net 's online documentation (search for: readdir function).) then try and get this.
Last edited by DarkBlood; February 10th, 2006 at 12:49.
change eregi_replace to str_replace if you want it to be case-sensitiveCode:$badwords = file("./badwords.txt"); foreach($badwords as $badword) { $filterthis = eregi_replace($badword, "", $filterthis); }
http://www.j-fx.ws - free website templates
http://www.j-fx.ws/tagbox/ - my shoutbox script
http://www.j-fx.ws/ffh/ - my file host script
great, thanks BeIIy!!
You could do what BeIIy did but here is what I did.
[php]
<?php
include("config.php");
global $text;
$text = str_replace("word", "**it", $text);
$text = str_replace("word", "**ck", $text);
$text = str_replace("word", "****er****er", $text);
?>[/code]
I named that file filter.php so what you do is when you have the user post, just include filter.php and when they post the file or whatever you want to have filtered, have a field that is the message that they're posting <input type="text" name=text> the query would be like
mysql_query("INSERT INTO table_name (blah, blah1, blah2, text) VALUES ('$blah', '$blah1', '$blah2', '$text')");
Than in the database it'll replace whatever is in the textfield with what you set it to in the filter.php file.
just got the time to try BeIIy's code out and it doesnt work
and stuffradio, thanks but thats not what i wanted. I wanted it to get each line of a file and put it into an array.PHP Code:$badwords = file("./includes/bad.txt");
foreach($badwords as $badword) {
$fullabrv = eregi_replace($badword, "", $fullabrv);
}
Whoops. I forgot that it leaves the linebreak characters on each line.
That should work. lolCode:$badwords = file("./badwords.txt"); foreach($badwords as $badword) { $word = str_replace("\r","",str_replace("\n","",$badword)); $filterthis = eregi_replace($word, "", $filterthis); }
http://www.j-fx.ws - free website templates
http://www.j-fx.ws/tagbox/ - my shoutbox script
http://www.j-fx.ws/ffh/ - my file host script
yep, that works. thanks loadsOriginally Posted by BeIIy
One more thing if you dont mind
how do i replace them with asterix's (like the f word would be replaced with ****, the b word would be replaced with *****)?
Code:$badwords = file("./badwords.txt"); foreach($badwords as $badword) { $word = str_replace("\r","",str_replace("\n","",$badword)); $stars = ""; for ($i = 1; $i <= strlen($word); $i++) { $stars .= "*"; } $filterthis = eregi_replace($word, $stars, $filterthis); }
http://www.j-fx.ws - free website templates
http://www.j-fx.ws/tagbox/ - my shoutbox script
http://www.j-fx.ws/ffh/ - my file host script
works like a charm BeIIyreally appreciated
![]()
Bookmarks