1

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
  • function naming and parameters are a disaster yes but as PHP is a disaster by itself anyway... </controversial> Commented Dec 15, 2008 at 13:19
  • I have to say, I strongly agree to this :) Commented Dec 15, 2008 at 13:56

3 Answers 3

2

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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?

Comments

1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.