Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 136,582 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,940 people online right now. Registration is fast and FREE... Join Now!




badwordfilter

 
Reply to this topicStart new topic

badwordfilter

ajaycode
6 Oct, 2008 - 04:22 AM
Post #1

New D.I.C Head
*

Joined: 9 Aug, 2008
Posts: 42

QUOTE

Hi everybody i wrote bad word filter program i throws error
pls help me
thanks in Advace







CODE

<?
//echo "ajay";
class swearfilter
{
    static $words = array("dirty","notgud","waste","bad","useless","handsome"
        // TODO: Enter bad words here like so: "bad",
        );
    
    function replace($haystack)
    {
                // Set the replacements
        $replacements = array("?", "!", "*", "@", "#", "*");
        
                // Loop through each and every word in the $words array
        foreach(swearfilter::$words as $needle)
        {
            $replace = '';
            // Create our replacement string by string length
            for($i=0; $i<strlen($needle); $i++)
            {
                $radnum = rand(0, 5);
                $replace .= $replacements[$radnum];
            }
            
            // Search for the current word and replace
            $haystack = str_ireplace($needle, $replace, $haystack);
        }
                // Return the "clean" text
        return $haystack;
    print_r($words);
    }
}
?>

User is offlineProfile CardPM
+Quote Post

Hary
RE: Badwordfilter
6 Oct, 2008 - 04:48 AM
Post #2

D.I.C Head
**

Joined: 23 Sep, 2008
Posts: 205



Thanked: 15 times
My Contributions
Edit: need to read the code better, never mind

What is the error it throws, on what line? The error does tell you what is wrong... (and it helps us find it, without copying, editing and running your code)

This post has been edited by Hary: 6 Oct, 2008 - 04:50 AM
User is offlineProfile CardPM
+Quote Post

ghqwerty
RE: Badwordfilter
6 Oct, 2008 - 09:39 AM
Post #3

D.I.C Regular
Group Icon

Joined: 8 Aug, 2008
Posts: 341



Thanked: 8 times
Dream Kudos: 25
My Contributions
$haystack = str_ireplace($needle, $replace, $haystack);

just a guess but shouldnt that be

$haystack = str_replace($needle, $replace, $haystack);
User is offlineProfile CardPM
+Quote Post

Hary
RE: Badwordfilter
6 Oct, 2008 - 11:52 AM
Post #4

D.I.C Head
**

Joined: 23 Sep, 2008
Posts: 205



Thanked: 15 times
My Contributions
No:


str_ireplace
(PHP 5)
str_ireplace — Case-insensitive version of str_replace().

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/3/08 12:32AM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month