I just run the microtime benchmark test 50 times side by side against the preg_match in the if and filter_var_array , checking the exact same reset data, here are the results of the micro session:
filter_var_array microtime: 0.000834226608276 preg_match microtime: 0.000180006027222
filter_var_array looks pretty, but 4-8 times slower than preg_match , so if you have a high traffic site and prefer fast code, I would recommend preg_match .
However, if you like good clean code and it doesn't matter how it works, use filter_var_array , which can be more manageable to apply simple filters to many form requests and form inputs.
But you can also achieve this ease by writing the preg_match function for different scenarios, such as email or alphanumeric, but remember the safety of preg_match when writing a regular expression, for example:
http://blog.php-security.org/archives/76-Holes-in-most-preg_match-filters.html
I would like to see the empathy of using memory on both.
Hope this helps
source share