tags:

views:

263

answers:

3

Why would I want to use PHP's filter library? Why wouldn't I?

It seems to try and do a bit of clean-up (it's awful when you have to work with regular expressions), but on the other hand function naming and parameter constants seem to be a disaster, if you ask me. It must have been included in PHP for a reason, but I just don't seem to like it. What am I missing?

Later edit:
Regarding GaryF's answer, I wish to explain a bit why I don't like this function. This isn't about using it in "my case" if it fits. This is about using it wherever it fits. There's a high chance of needing a filter that won't fit PHP's functions, so I'll have to create my own filter. In that case, the application will use two completely different kinds of functions for data filtering. I consider that to be a much worse practice than just inventing a better wheel.

+2  A: 

Probably the best resource for this is the tutorial linked to from the PHP manual page: http://devolio.com/blog/archives/413-Data-Filtering-Using-PHPs-Filter-Functions-Part-one.html

It's decent enough for simple filtering, but if you don't find your use-case on that page it probably isn't for you.

GaryF
+2  A: 

My stance is that the concept of filtering input data is flawed on a conceptual level. See my reply to the almost similar question What’s the best method for sanitizing user input with PHP?

troelskn
+1  A: 

It's about using a well-tested data filtering framework to prevent XSS and SQL Injection attacks.

If you look at all the possibilities, that is the kind of filtering you don't want to implement yourself.

http://www.php.net/manual/en/intro.filter.php

Vincent