how to replace sex with *** in a file

Discussion in 'Programming' started by nevret2, Jun 9, 2008.

  1. #1
    hello,

    i want, if there is a word called sex in my website, it will replace it with *** how can i do this? what is the code for this? hope someone can help me, thnx
     
    nevret2, Jun 9, 2008 IP
  2. blueparukia

    blueparukia Well-Known Member

    Messages:
    1,564
    Likes Received:
    71
    Best Answers:
    7
    Trophy Points:
    160
    #2
    Are you using PHP? Or some other server side language? or do you want to do this with Javascript?

    Its easy enough to do though, php would probably be the better option, so it doesn't show up in the source.
     
    blueparukia, Jun 9, 2008 IP
  3. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #3
    str_replace('sex','***',$content);

    Peace,
     
    Barti1987, Jun 9, 2008 IP
  4. WhaLberg

    WhaLberg Peon

    Messages:
    44
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    if there are other words you want to censor, you can use array() function.

    example:
    
    $replace = "***"
    $censoredwords = array("sex", "word2", "word3", "word4");
    foreach ($censoredwords AS $censoredword)
    {
        $mainvar = str_replace($censoredword, $replace, $mainvar);
    }
    
    PHP:
     
    WhaLberg, Jun 9, 2008 IP