We are spoilt for choice when to use the htmlentities() and the htmlspecialchars() as we won't be always dealing with one same value. For example, we might be outputting on page different values of $var each time from our mysql db or outputting on our page different values of $var (value that the user just submitted on our webform).
In short, we don't know what the value of $var will be and so we don;t know whether to use the htmlentities() or the htmlspecialchars().
For our learning purpose, is there any chance you can write two lines of code (a custom function) that checks the $var value to see whether it has chars that are best to use htmlentities() over the htmlspecialchars() or best to use htmlspecialchars() over the htmlentities() ? And then our custom function can use the appropriate function out of the two built-in functions (htmlentities()/htmlspecialchars()). That way, we don't use' the wrong built-in function, out of the two, unnecessarily.
What you say ?
Have you ever tried building something like this, ever ?
Anyone else welcome to give this custom function building a go. I'm still at beginner level and so this is a bit over my head.