Wednesday, May 16, 2012

PHP Word Censor help, censor word based on a criteria using regex

Hi all im trying to build a regular expression which will sustain the following criteria.

Word to be censored in this example "view".
Character to be used after censor: "%", since "*" mess up my post formatting.

Examples of word use:




I went to see the great view

The view was great wasn't it.

Example after word censor:




I went to see the great %%%%

The %%%% was great wasn't it.

Here is some code I have:

$string = preg_replace_callback('/\s*'. preg_quote($word, '\\') .'\s*/is', 'bbcode_callback_censored', $string);

Trouble is this matches everything right now since i use "*" in the regex ater "\s". Any ideas what I could do to fulfill my criteria?

No comments:

Post a Comment