Comments are available to members only. Sign up or Log in to view these comments.
Main Topics
Browse All Topicshi,
I have made a flash message board. The chat room uses php to do the scripting back-end stuff
I have a built in swear word and detection function in my php that searches and removes swear words in comments.
The problem is if I have a word like “assignment” the php removes the ass part from the “assignment”. So instead of getting “assignment” I get “***ignment”. What I need is some form of swear word detection and remove function that only removes swear words but dose not remove swear words that are part of a word. So that it would remove the word ass if it was on its own but not if it was in the word assignment. My code for the php is as follows:
Sorry about all the long code but if I don’t past it all it wont make any sense also sorry about the swear words that’s for demonstration purposes. The swear word detection function is at the end of the code.
--------------------------
<?php
$SplitThis = "_________________________
$TopicsPerPage = 11;
$Submit = $HTTP_POST_VARS[Submit];
$Category = $HTTP_POST_VARS[Category];
$readDirGlobal = $HTTP_POST_VARS[readDirGlo
$readDir = $HTTP_POST_VARS[readDir];
$numLow = $HTTP_POST_VARS[NumLow];
$numHigh = $HTTP_POST_VARS[NumHigh];
$Category = ereg_replace("[^A-Za-z1-9]
$Submit = ereg_replace("[^A-Za-z]", "", $Submit);
$readDir = ereg_replace("[^A-Za-z]", "", $readDir);
$readDirGlobal = ereg_replace("[^A-Za-z]", "", $readDirGlobal);
if ($Submit == 'SubmitNew' OR $Submit == 'SubmitReply') {
$Name = $HTTP_POST_VARS[Name];
$Subject = $HTTP_POST_VARS[Subject];
$Message = $HTTP_POST_VARS[Message];
$File = $HTTP_POST_VARS[File];
$Name = ereg_replace("[^A-Za-z0-9 ]", "", $Name);
$Subject = ereg_replace("[^A-Za-z0-9 \.\-\:]", "", $Subject);
$Message = str_replace("-", "%2D", $Message);
$Message = ereg_replace("[^A-Za-z0-9 \@\.\/\%\'\[\]\:\\n\/\r ]", "", $Message);
$Message = str_replace("%2D", "-", $Message);
$Name = stripslashes($Name);
$Subject = stripslashes($Subject);
$Message = stripslashes($Message);
$Checked = "Yes";
$Message = preg_replace("/([^\w\/])(w
$Message = preg_replace("/([\w]+:\/\/
$Message = preg_replace("/([\w-?&;#~=
$Message = BadWordFunc($Message);
$Name = BadWordFunc($Name);
$Subject = BadWordFunc($Subject);
$Message = str_replace("[","<",$Messa
$Message = str_replace("]",">",$Messa
$Message = str_replace("{","'",$Messa
$Message = str_replace("}","'",$Messa
}
if ($readDir == "Yes") {
readDirectory($Category, $numLow, $numHigh, $SplitThis, $TopicsPerPage);
}
if ($Submit == 'SubmitNew' AND $Checked == 'Yes') {
submitNew($Category, $Name, $Subject, $Message, $numLow, $numHigh, $SplitThis, $TopicsPerPage);
}
if ($Submit == 'SubmitReply' AND $Checked == 'Yes') {
submitReply($Category, $Name, $Subject, $Message, $File, $numLow, $numHigh, $SplitThis, $TopicsPerPage);
}
if ($readDirGlobal == "Yes") {
$Results1 = CountGlobals("Category1", $SplitThis);
$Results2 = CountGlobals("Category2", $SplitThis);
$Results3 = CountGlobals("Category3", $SplitThis);
$Results4 = CountGlobals("Category4", $SplitThis);
$Results5 = CountGlobals("Category5", $SplitThis);
$Results6 = CountGlobals("Category6", $SplitThis);
$Results7 = CountGlobals("Category7", $SplitThis);
$GlobalPosts = $Results1[0] + $Results2[0] + $Results3[0] + $Results4[0] + $Results5[0] + $Results6[0] + $Results7[0];
$GlobalReplys = $Results1[1] + $Results2[1] + $Results3[1] + $Results4[1] + $Results5[1] + $Results6[1] + $Results7[1];
print "&GlobalTopics=$GlobalPost
}
function submitNew($Category, $Name, $Subject, $Message, $numLow, $numHigh, $SplitThis, $TopicsPerPage) {
$TimePart = time();
$SubjectPart = str_replace(" ", "-", $Subject);
$NamePart = str_replace(" ", "-", $Name);
$filename = $TimePart."_".$NamePart."_
$Today = (date ("l dS of F Y ( h:i:s A )",time()));
$Input = "Thread=Subject: <b>$Subject</b><br>Name: <b>$Name</b><br>Message: $Message<br><i><font size=\"-1\">Date: $Today</font></i><br>$Spli
$pathToFile = $Category."/".$filename;
$fp = fopen( $pathToFile,"w");
fwrite($fp, $Input, 4000);
fclose( $fp );
chmod ($pathToFile, 0666);
print "&Status=Your message was sent&";
readDirectory($Category, $numLow, $numHigh, $SplitThis, $TopicsPerPage);
loadNewReply($pathToFile);
}
function submitReply($Category, $Name, $Subject, $Message, $File, $numLow, $numHigh, $SplitThis, $TopicsPerPage) {
$PathName = $Category."/".$File;
$Today = (date ("l dS of F Y ( h:i:s A )",time()));
$newStuff = "<br><br>Subject: <b>$Subject</b><br>Name: <b>$Name</b><br>Message: $Message<br><i><font size=\"-1\">Date: $Today</font></i><br>$Spli
$fp = fopen( $PathName,"a");
fwrite($fp, $newStuff, 80000);
fclose( $fp );
print "&Status=Your reply has been sent&";
readDirectory($Category, $numLow, $numHigh, $SplitThis, $TopicsPerPage);
loadNewReply($PathName);
}
function readDirectory($Category, $numLow, $numHigh, $SplitThis, $TopicsPerPage) {
$handle = opendir($Category);
while (false !== ($topics = readdir($handle))) {
if ($topics != "." && $topics != "..") {
$topicName = $Category."/".$topics;
$topicTime = filemtime($topicName);
$topicArray[$topics] = $topicTime;
}
}
arsort($topicArray);
$numberOfTopics = sizeOf($topicArray);
print "&numTopicsAll=$numberOfTo
if ($numberOfTopics <= $TopicsPerPage) {
$Pages = 1;
}
if ($numberOfTopics > $TopicsPerPage) {
$Page = ($numberOfTopics / $TopicsPerPage);
$Pages = floor($Page)+1;
}
$PageNumber = $numHigh / $TopicsPerPage;
if ($numberOfTopics > $numHigh) {
$numDup = (($TopicsPerPage * $PageNumber));
$numLDup = ($numLow + 1);
}
if ($numberOfTopics <= $numHigh) {
$numDup = ($TopicsPerPage-($numHigh-
$numDup = (($numDup + $numLow));
$numLDup = ($numLow + 1);
}
$Count = 1;
foreach ($topicArray as $key => $value) {
$thisTopicName = $key;
$thisTopicTime = $value;
$thisTopicTime = date("n/j/Y", $thisTopicTime);
$nameArray = split ("_", $thisTopicName);
$TopicSubject = str_replace("-", " ", $nameArray[2]);
$TopicName = str_replace("-", " ", $nameArray[1]);
$TopicSubject = str_replace(".txt", "", $TopicSubject);
$topicCreated = date("n/j/Y", $nameArray[0]);
$topicStartedBy = $TopicName;
$fp = fopen( $Category."/".$thisTopicNa
$numReplysTopics = fread($fp, 80000);
fclose( $fp );
$numReplysTopicsArray = split ($SplitThis, $numReplysTopics);
$numReplysLocal = count($numReplysTopicsArra
$numReplysGlobal = $numReplysGlobal + $numReplysLocal;
print "&Topic$Count=$TopicSubjec
$Count = $Count + 1;
}
closedir ($handle);
print "&TotalPosts=$numReplysGlo
}
function loadNewReply($PathName) {
$fp = fopen( $PathName,"r");
$ForceIn = fread($fp, 80000);
fclose( $fp );
print "&$ForceIn&";
}
function CountGlobals ($Category, $SplitThis) {
$handle = opendir($Category);
while (false !== ($topics = readdir($handle))) {
if ($topics != "." && $topics != "..") {
$topicArray[$topics] = $topicTime;
}
}
$numberOfTopics = sizeOf($topicArray);
for($t=0;$t<$numberOfTopic
$thisFile = each($topicArray);
$thisTopicName = $thisFile[0];
$fp = fopen( $Category."/".$thisTopicNa
$numReplysTopics = fread($fp, 80000);
fclose( $fp );
$numReplysTopicsArray = split ($SplitThis, $numReplysTopics);
$numReplysLocal = count($numReplysTopicsArra
$numReplysGlobal = $numReplysGlobal + $numReplysLocal;
}
closedir ($handle);
$DataR = array($numberOfTopics, $numReplysGlobal);
return $DataR;
}
function BadWordFunc ($RemoveBadWordText) {
$RemoveBadWordText = eregi_replace("fuc?k|[kc]u
return $RemoveBadWordText;
}
?>
--------------------------
I have also tried this form of swear word detection on a guest book I made in flash:
--------------------------
<?
$Name = ereg_replace("[^A-Za-z0-9 ]", "", $Name);
$Email = ereg_replace("[^A-Za-z0-9 \@\.\-\/\']", "", $Email);
$Shout = str_replace("-", "%2D", $Shout);
$Shout = ereg_replace("[^A-Za-z0-9 \@\.\/\%\'\[\]\:\\n\/\r ]", "", $Shout);
$Shout = str_replace("%2D", "-", $Shout);
$Shout = str_replace("{", "'", $Shout);
$Shout = str_replace("}", "'", $Shout);
$Shout = str_replace("[", "<", $Shout);
$Shout = str_replace("]", ">", $Shout);
$Website = ereg_replace("[^A-Za-z0-9 \@\.\-\/\'\~\:]", "", $Website);
$Name = stripslashes($Name);
$Email = stripslashes($Email);
$Website = stripslashes($Website);
$new = $date_array[0] + $time_a;
$date = (date ("l dS of F Y ( h:i:s A )",time()));
$date = (date ("l dS of F Y ( h:i:s A )",time()));
$Submit = "Yes";
if ($Submit == "Yes") {
$filename = "ShoutBox-R.txt";
$fp = fopen( $filename,"r");
$OldData = fread($fp, 80000);
fclose( $fp );
$array_1 = array("****","ass");
$array_2 = array("****","***");
for($x=0;$x<3;$x++)
{
$Shout = str_replace($array_1[$x],$
}
$Shout=$Shout;
$Input = "</font><br>Name : $Name<br><font size=\"8\" color=\"#FFFF00\"><i>($dat
$New = "Shouts=$Input$OldData";
$filename = "ShoutBox-R.txt";
$fp = fopen( $filename,"w+");
fwrite($fp, $New, 80000);
fclose( $fp );
}
?>
--------------------------
To see the form and shout box the sites are:
http://www.rabidlemming.co
http://www.rabidlemming.co
Any help would be appreciated
Many thanks in advanced
Cheers
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Business Accounts
Answer for Membership
by: neorushPosted on 2004-03-05 at 02:35:03ID: 10521379
Comments are available to members only. Sign up or Log in to view these comments.