filters naughty words

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

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

filters naughty words

Post by 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 :(


New php-forum User
New php-forum User
Posts: 164
Joined: Tue Aug 27, 2002 8:25 pm
Location: Ontario, Canada

Post by 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.

User avatar
Posts: 1717
Joined: Sun Dec 29, 2002 5:03 am
Location: Portugal / Sweden

Post by 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");
$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);

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests