AdamH.us

Basic Word Censor in PHP

by on Feb.15, 2012, under TheScripters, Web Design

This is a really basic word censor that can be used in pretty much any PHP application. It’s pretty simple. I used it in KPFanWorld while I was initially writing it. It can obviously be changed and modified.

In this example, it would turn the word “string” into ****** so that the original word is not visible. This can either be applied as the text is being inserted to a database or as it’s being displayed. The latter option would be ideal if you plan on having the option for users to turn it off individually. If that’s not planned, then for performance it would be better to modify the text as it’s going into the database.

It could be modified further to have a replacement for each word specified by the administrator.

Both sets values can be returned from a database. A good idea might be to store the value sets in a single table called “censor” and have one field as “word” and the other as “replace” and populate the arrays (or apply the censor) in a while loop.

Just make sure to use correct query function (pgsql_query or mysql_query as examples) in order for it to work.

© 2012, AdamH.us. All rights reserved. Please link back if you use it!

:, , ,

Comments are closed.

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!