How do you implement a good profanity filter?

后端 未结 21 2738
误落风尘
误落风尘 2020-11-22 04:27

Many of us need to deal with user input, search queries, and situations where the input text can potentially contain profanity or undesirable language. Oftentimes this needs

21条回答
  •  梦谈多话
    2020-11-22 05:05

    I'm a little late to the party, but I have a solution that might work for some who read this. It's in javascript instead of php, but there's a valid reason for it.

    Full disclosure, I wrote this plugin...

    Anyways.

    The approach I've gone with is to allow a user to "Opt-In" to their profanity filtering. Basically profanity will be allowed by default, but if my users don't want to read it, they don't have to. This also helps with the "l33t sp3@k" issue.

    The concept is a simple jquery plugin that gets injected by the server if the client's account is enabling profanity filtering. From there, it's just a couple simple lines that blot out the swears.

    Here's the demo page
    https://chaseflorell.github.io/jQuery.ProfanityFilter/demo/

    ass will fail but password will not

    result

    *** will fail but password will not

提交回复
热议问题