Question

I am trying to modify my coding styles and am getting used to using filter_var($input,FILTER_SANITIZE_FULL_SPECIAL_CHARS). I have gotten used to using the other filter_var options with no difficulty.

In this specific case though, FILTER_SANITIZE_FULL_SPECIAL_CHARS can only be used in newer versions of php than the one my hosting provider uses. We are still on php 5.2.17. My question is, how do I accomplish the same task with the same reliability as using this easy call to the filter_var function?

Was it helpful?

Solution

From the best of my knowledge, the only solution I could come up with is as follows. Still not sure if it's functionally identical or not, but my testing has shown it to work much the same....

filter_var($input, FILTER_SANITIZE_STRING,FILTER_FLAG_ENCODE_AMP|FILTER_FLAG_ENCODE_HIGH|FILTER_FLAG_ENCODE_LOW);

NOTE: When using more than one filter_var flag, you separate each flag after the first one with a pipe instead of a comma, or filter_vars breaks.... Took a while to figure that one out! :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top