What are the potential benefits of creating a domain-check feature in PHP for a website?

Creating a domain-check feature in PHP for a website can help ensure that only valid domains are accepted for certain actions, such as user registrations or form submissions. This can help prevent spam or malicious activity on the website by verifying the legitimacy of the domain being used.

<?php
function checkDomain($domain) {
    if (filter_var($domain, FILTER_VALIDATE_DOMAIN)) {
        return true;
    } else {
        return false;
    }
}

// Example usage
$domain = "example.com";
if (checkDomain($domain)) {
    echo "Valid domain";
} else {
    echo "Invalid domain";
}
?>