Hi,
Out of experience which is better to use
filter_input(INPUT_GET, ‘my_string’, FILTER_SANITIZE_STRING);
Or a regular expression preg_match for sanitizing user in-putted data ?
Hi,
Out of experience which is better to use
filter_input(INPUT_GET, ‘my_string’, FILTER_SANITIZE_STRING);
Or a regular expression preg_match for sanitizing user in-putted data ?
I prefer filter_input over regex for this - as it is easier to read.
It depends on what you want to do and which PHP version you're using. *filter_input* is a convenient method to validate some input data for a well known target format such as URLs, IP-addresses or eMail-addresses, but might only be available for PHP >= 5.2.
In order to validate custom data (e.g. comma-separated values string), a regular expression would be more appropriate and therefore the way to go.
The do different things. FILTER_SANITIZE_STRING only strips tags and optionally does a number of things.
preg_match matches an arbitrary regular expression. You probably meant preg_replace, which by the way you can use the filter extension through FILTER_CALLBACK.