How can the provided code be simplified for checking the validity of strings in PHP?

The provided code for checking the validity of strings in PHP can be simplified by using the built-in function `filter_var()` with the `FILTER_VALIDATE_EMAIL` flag to validate email addresses and the `FILTER_VALIDATE_URL` flag to validate URLs. This approach eliminates the need for custom regular expressions and simplifies the code.

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

if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
    echo "Email is valid.";
} else {
    echo "Email is invalid.";
}

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