Filter_input (INPUT_GET, 'my_string, FILTER_SANITIZE_STRING); VS regex Preg Match PHP

Experience that is better to use

filter_input(INPUT_GET, โ€˜my_stringโ€™, FILTER_SANITIZE_STRING);

Or a preg_match regex to sanitize user data?

+3
source share
3 answers

It depends on what you want to do and what version of PHP you are using. filter_input is a convenient method for checking some input data for a well-known target format, such as URLs, IP addresses or email addresses, but may only be available for PHP> = 5.2.

To validate user data (for example, a string of values โ€‹โ€‹separated by commas), a regular expression would be more appropriate and therefore a way to jump.

+3

filter_input regex - .

+5

. FILTER_SANITIZE_STRING .

preg_matchmatches an arbitrary regular expression. You probably meant preg_replacethat, by the way, you can use the filter extension through FILTER_CALLBACK.

+3
source

Source: https://habr.com/ru/post/1754408/


All Articles