How can PHP be used to encrypt email addresses on a website for spam protection?

To encrypt email addresses on a website for spam protection, you can use PHP to encode the email address in a way that is not easily recognizable by spam bots. One common method is to use a combination of string manipulation functions and base64 encoding to obfuscate the email address.

<?php
function encrypt_email($email) {
    $encrypted_email = '';
    
    for ($i = 0; $i < strlen($email); $i++) {
        $encrypted_email .= "&#" . ord($email[$i]) . ";";
    }
    
    return $encrypted_email;
}

$email = "example@example.com";
$encrypted_email = encrypt_email($email);

echo "<a href='mailto:" . $encrypted_email . "'>" . $encrypted_email . "</a>";
?>