I currently call a function to filter some HTML in PHP like this FilterHTML($string) I found a CLASS that I would like to use though and I do not know much about OOP and classes at all.
I would like to just use this class in my existing function call because the function is already called sitewide in a lot of file so I would like to do it like this:
function FilterHTML($string) {
$filter = new HtmlFilter;
$safeHTML = $filter->filter($contents);
echo $safeHTML . "\n";
}
FilterHTML($string);
FilterHTML($string);
FilterHTML($string);
FilterHTML($string);
...
I realize $filter = new HtmlFilter; is creating a new object but this is where I am lost,
Lets say I call the FilterHTML($string) function 10 times on the same page, do I need to be creating this new object new HtmlFilter; all 10 times or can it be called 1 time then use this classes functions 10 times or reate a new object and then use the functions all 10 times?
Would I use it like this or like above
$filter = new HtmlFilter;
function FilterHTML($string) {
$safeHTML = $filter->filter($contents);
echo $safeHTML . "\n";
}
FilterHTML($string);
FilterHTML($string);
FilterHTML($string);
FilterHTML($string);
...