Write a PHP script that checks if a given string is a valid email address.

<?php
function isValidEmail($email) {
    return filter_var($email, FILTER_VALIDATE_EMAIL) !== false;
}

$testEmail = "[email protected]";

if (isValidEmail($testEmail)) {
    echo "$testEmail is a valid email address.";
} else {
    echo "$testEmail is not a valid email address.";
}
?>
  • The script defines a function isValidEmail that uses the filter_var function with the FILTER_VALIDATE_EMAIL filter to check if a given string is a valid email address.
  • The script then calls the function with a sample email address ($testEmail) and prints the result.

Post your Answer