What are some potential pitfalls when validating URLs in PHP, especially when considering different domain extensions like .museum?

When validating URLs in PHP, it's important to consider all possible domain extensions, including less common ones like .museum. One potential pitfall is only allowing for traditional domain extensions in your validation logic, which could result in valid URLs being rejected. To avoid this issue, use a regular expression that allows for a wide range of domain extensions.

$url = "http://example.museum";

if (preg_match('/^(https?|ftp):\/\/([a-z0-9-]+\.?)+\.[a-z]{2,4}$/i', $url)) {
    echo "Valid URL";
} else {
    echo "Invalid URL";
}