Censor Bad And Abusive Words By Replacing Them With Stars Using PHP

LEVEL: Beginner

Whats in this post?

  1. Code
  2. Output
  3. Background and Explanation of the code

Code


To copy code: Click  View Source “View Source” on the right of this code snippet.

Background and Explanation of the code


This program in PHP searches for bad or abusive words in a given string and replace them with a sequence of stars ‘*’. The list of abusive words can be taken from a central database. The code can be used in situations where a control over the user inputs is necessary such as in forums, blogs etc. to censor the user inputs.
Output:
This is a test paragraph. Some bad words: ****, ****