Class File Creation Tutorial Learn PHP OOP
Learn Object Oriented Programming (OOP) in PHP. OOP is used to tap into class files that house your software logic in an organized, extensible, dynamic, reusable framework of sorts. You can use class files to create very robust custom frameworks in PHP. JavaScript and ActionScript 3.0 have similar flow to PHP so it also is easy to make external reusable modules for those languages as well. I also threw in a PHP bad word filter function, so you get a bit of string manipulation logic and array handling thrown in as bonus material.
curseFilter.php (class file)
<?php
class curseFilter {
function clean($str){
$curzwords = array("jerk","buttface","idiot");
$replacers = array("j**k","cuteface","id**t");
$cleanStr = str_ireplace($curzwords, $replacers, $str);
return $cleanStr;
}
}
?>
example.php (demo usage file)
<?php
include_once("curseFilter.php");
$curseFilter = new curseFilter;
// -----------------------
$string = "you jerky idiot.";
$clean_str = ($curseFilter -> clean($string));
echo $clean_str;
?>