PHPfreaks your script woks fine. However I would like to make a few modifications and apply it inside input fields, how do I do that? Lets say my input fields are as foolows:
<input type='text' name='badwords' /> <!-- where do I put php on this input field as a php include file-->
<?php
$badwords = array('bad1', 'bad2', 'bad3', 'ass'); $text = 'This is a test. Ass. Grass. bad1.'; function filterBadwords($text, array $badwords, $replaceChar = '*') { return preg_replace_callback( array_map(function($w) { return '/\b' . preg_quote($w, '/') . '\b/i'; }, $badwords), function($match) use ($replaceChar) { return str_repeat($replaceChar, strlen($match[0])); }, $text ); } echo filterBadwords($text, $badwords);
?>