Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

filters naughty words

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

filters naughty words

Postby robbied » Wed Mar 19, 2003 9:16 am

so i had a funct that worked great and now it doesn't seem to work.

i am looking to read in a file of bad words (one per line) and then check a string for each word. if found, i replace the bad word with some *** and we're done.

Has anyone done this code before ? I can do it in perl in 4 lines, I love PHP now and am stuck :(

Thanks
Rob
User avatar
robbied
New php-forum User
New php-forum User
 
Posts: 7
Joined: Wed Feb 19, 2003 8:35 am
Location: Victoria, BC

Postby Xerpher » Wed Mar 19, 2003 9:30 am

I haven't actually done this before, but you'll need to use fread() to read the file and eregu() to see if the word is in your phrase, if you can't figure it out tell me and I'll whip up a sample.
Xerpher
New php-forum User
New php-forum User
 
Posts: 164
Joined: Tue Aug 27, 2002 8:25 pm
Location: Ontario, Canada

Postby gesf » Sun Mar 23, 2003 1:37 am

hey robbied.
I´m bad in English and not a pro in php. I´ve just made a mix with some codes.
Hope it helps.

Code: Select all
// Your file
$file="your file here";

// The bad and the respective censored word
$badword = "blabla";
$censorword = "bl***a";

// To search in the file
$result = explode($badword);

// Open file for read
$fp = fopen ($file, "r+") or die ("Error opening $file");
flock($fp,2);
$fp=fread($fp, filesize($file));
fclose ($fp);


// Replacing bad words
// "$textplace" -> the place where the text will be entered and replaced

$textplace = strip_tags($textplace,"");
$textplace = str_replace("$badword","$censorword",$textplace);
$textplace = stripslashes($textplace);
User avatar
gesf
Moderator
Moderator
 
Posts: 1717
Joined: Sun Dec 29, 2002 5:03 am
Location: Portugal / Sweden


Return to PHP coding => General

Who is online

Users browsing this forum: yetticaretti and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.