is URL valid or not [duplicate]

2019-01-24 00:29发布

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 referes to an existing page of the web or other kind of files. It just should exist

2条回答
兄弟一词,经得起流年.
2楼-- · 2019-01-24 01:11

You can check whether URL is valid or not using parse_url function which would return false if URL is not valid and an array otherwise.

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

pretty easy way, huh? :)

查看更多
Deceive 欺骗
3楼-- · 2019-01-24 01:30
<?php

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


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

this does not check tlds though

查看更多
登录 后发表回答