Validating a URL with filter_var() in PHP


Check if a given string is a valid URL.

Source Code

$url = "https://www.example.com";
if (filter_var($url, FILTER_VALIDATE_URL)) {
    echo "This is a valid URL.";
} else {
    echo "Invalid URL.";
}
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments