Are there any specific PHP functions or methods that are recommended for validating URLs and ensuring they are in the correct format?

When validating URLs in PHP, it's important to ensure they are in the correct format to prevent security vulnerabilities or errors in your application. One recommended method for validating URLs is to use the `filter_var()` function with the `FILTER_VALIDATE_URL` filter. This function will check if the URL is in a valid format according to RFC 2396.

$url = "https://www.example.com";

if (filter_var($url, FILTER_VALIDATE_URL)) {
    echo "URL is valid";
} else {
    echo "URL is not valid";
}