Listening Video
Learn to build bad word or harmful character filter functions and data filtration systems for user input. We are using the str_ireplace() php function fed with arrays.
Lesson Code
<?php
function badWordFilter($data){
$originals = array("douche","punch","damn");
$replacements = array("friend","love","wow");
$data = str_ireplace($originals,$replacements,$data);
return $data;
}
$myData = "Hi douche, damn I want to punch you for a good cause!";
$cleaned = badWordFilter($myData);
echo $cleaned;
?>
0 Response to "PHP Tutorial Bad Word Filter Function and Harmful Character String Replacement System"
Post a Comment