19

Possible Duplicate:
what is the best way to check if a Url exists in PHP ?`

I'm looking for a function that returns TRUE or FALSE in php, either the URL is valid or not.

isValidURL($url); I think that simple... That would take into count all kind of URL possible.

By valid I want it to refer to an existing page of the web or other kind of files. It just should exist.

4

2 に答える 2

60
<?php

$url = "http://stack*overflow.org";


if(filter_var($url, FILTER_VALIDATE_URL) === FALSE)
{
        echo "Not valid";
}else{
        echo "VALID";
}
?>

ただし、これはtldsをチェックしません

于 2011-07-24T13:19:04.937 に答える
2

URLが有効でない場合parse_urlは返す関数を使用して、URLが有効かどうかを確認できます。falsearray

function isValidURL($url) { return (bool)parse_url($url); }

かなり簡単な方法ですよね?:)

于 2011-07-24T13:06:15.760 に答える