First I'll show the function:
function validate($data, $filter){
if(!filter_var($data, $filter))
{
return 'Filter used:'.$filter;
}
else
{
return 'good';
}
}
When I use this function it will look like this:
$email = '[email protected]';
echo validate($email, FILTER_VALIDATE_EMAIL);
Output is:
Filter used: 274
The problem is that I want the output to be:
Filter used: FILTER_VALIDATE_EMAIL.
To get the actual constant name you probably need to pass the filter as a string and use
constant():Then use it like:
I got to thinking about multiple flags, and I was bored. This could get really messy but for simple filters it works: