SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2000
    Posts
    132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hey guys.
    i'm trying to find the best way to censor a guestbook.
    I am creating a remotely hosted guestbook system, and I need to find the most efficient way of checking the fields:

    $name
    $email
    $homepage
    $userinput1
    $userinput2
    $userinput3
    $userinput4
    $userinput5
    $message

    for a list of keywords.
    It may be a long list, so maybe I could use fopen with an explode to separate them. So if you could help me with this, that would be great.
    Also, How would I then put all the terms into an array, and check the above variables for those words, and if they exist, replace them with a string like: <img src='censored.gif'>.
    Thanks for your help.
    -AJ

  2. #2
    SitePoint Zealot
    Join Date
    Jul 2000
    Posts
    132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No one have any ideas?...

    AHHHHH!


    -aj

  3. #3
    I believe you have my stapler. scrubz's Avatar
    Join Date
    Feb 2001
    Location
    Van down by the river
    Posts
    254
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've done something like this in ASP and JavaScript, but not PHP.

    Basically I put the "bad" words in an array, checked each input to see if a word in the input matched one of the words in the array, and then replaced it with a different word. To replace it with a gif, you could replace the bad word with a certain code when storing into the database, such as
    <-censored->. Then when displaying the entry on the page, search for <-censored->, and replace it with the gif.

    This probably isn't a lot of help to you since it isn't PHP specific, but I'm sure it can be done.

  4. #4
    imagine no limitations exbabylon's Avatar
    Join Date
    Dec 2000
    Location
    Idaho, USA
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you could do something like this:

    PHP Code:
    // Badword IMG URL
    $url "http://www.mydomain.com/images/badword.gif";
    // open file

    $badwords explode(',',$file);


    $i 0;

    while(
    "$badwords[$i]!= ""){
    eregi_replace("$badwords[$i]","<img src=$url>");
    $i++;

    that "might" work... I never have played with text type files.. I've always used MySQL... but its a start mabey?
    Blamestorming: Sitting around in a group discussing why a deadline was missed or a project failed and who was responsible.

    Exbabylon- Professional Internet Services

  5. #5
    SitePoint Zealot
    Join Date
    Jul 2000
    Posts
    132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    exbabylon...
    yes, thanks.
    thats a good start, anyway.
    ok, well i tried this, and the code I have at the moment is:
    Code:
    $fileopen= "badwords.txt";
    
    // open file
    $wordsfile = fopen($fileopen, "r");
    
    $badwords = explode(',',$fileopen);
    $i = 0;
    
    while("$badwords[$i]" != ""){
    eregi_replace("$badwords[$i]","<img src=images/censorship.gif>", $message);
    $i++;
    
    fclose($fileopen);
    I think quite a bit is wrong, and it is () because it doesn't work! Any clues?
    Cheers -aj
    btw, the error is on the fclose bit.

  6. #6
    SitePoint Zealot cokeman's Avatar
    Join Date
    Dec 2000
    Location
    So. California
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    two comments...

    1) shouldn't the while loop's { brace be closed somewhere, like after the i++, as in exbabylon's code?

    2) when you use fclose(), i think you should specify the file pointer, not the filename.. so i think it should be fclose($wordsfile), not fclose($fileopen).. to me, it'd probably make more sense to reverse your naming scheme.. i.e.,

    $wordsfile = "badwords.txt";
    $fileopen = fopen($wordsfile, "r");

    then, your current fclose statement would work fine

  7. #7
    SitePoint Zealot
    Join Date
    Jul 2000
    Posts
    132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    cokeman,
    thanks, but still.. the same error.
    I had closed the while loop, but in the wrong place.

    What I have now is:
    Code:
    if ($usergbcensorship == 'y') {
    
    $wordsfile = "badwords.txt";
    
    // open file
    $openfile = fopen($wordsfile, "r");
    
    $badwords = explode(',',$openfile);
    $i = 0;
    
    while("$badwords[$i]" != ""){
    
    $message = eregi_replace("$badwords[$i]","<img src=images/censorship.gif>", $message);
    $i++;
    }
    
    fclose($wordsfile);
    At the moment, the error I get is:
    Warning: Supplied argument is not a valid File-Handle resource in printposts.php on line 96
    This is the line of fclose.
    Anyone have any ideas? This is really frustrating me!

    Thanks,
    -aj
    Last edited by AJ; Mar 16, 2001 at 15:30.

  8. #8
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I will assume this post was meant for the thread about changing links. No problem.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  9. #9
    SitePoint Zealot cokeman's Avatar
    Join Date
    Dec 2000
    Location
    So. California
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Like I said earlier, you should be using fclose on the file pointer, not the filename. $wordsfile in your code is just a string "badwords.txt" while $openfile is the filepointer. When you do the fclose, you have to do it on the filepointer, so your statement would be:

    fclose ($openfile);

    I guess I introduced more confusion by asking you to change the naming scheme earlier.. sorry


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •