Not logged in
Home/Tutorials/Creating a Function
a year ago
Creating a Function
Content by: Steve Stewart
Posted a year ago with 562 views
Here we create a function containing an array of bad words we don't want to allow through our string.
For this demonstration I have three but this can be any number, just remember if you add more, you have to add more to the replace array.
$words = array("bullets","dick","damn");
$replace = array("snowboard","friend","amazing");
$string = str_replace($words,$replace,$string);
$mystring = "Hi dick, damn you want to play with the bullets";
$cleaned = badWords($mystring);