Search code examples
phpfilter-var

Why FILTER_VALIDATE_URL return FALSE for only this url?


i have the following code:

$url = "http://icons3.iconfinder.netdna-cdn.com/data/icons/pool/poolbird.png";

if (filter_var ($url, FILTER_VALIDATE_URL) === FALSE) {

    echo "Invalid Url";
    exit;

} else {

    echo "Works!";
}

This displays:

invalid url (FALSE)

for the above url, but not for other simpler urls. Is this a bug? you can even access the image.

And the most important is what's the solution for this?

Thanks


Solution

  • PHP < 5.2.13 contains a bug in FILTER_VALIDATE_URL that considers urls containing the '-' (http://bugs.php.net/51192). You either need to upgrade your copy of php or use a different filtering mechanism.