What are the best practices for formatting and displaying email addresses in PHP?
When displaying email addresses in PHP, it is important to format them properly to prevent email harvesting by spammers. One common practice is to use HTML entities to obfuscate the email address. This involves encoding the "@" symbol as "@" and the "." symbol as "." to make it harder for bots to recognize and collect the email address.
<?php
$email = 'example@example.com';
$obfuscated_email = str_replace(['@', '.'], ['&#64;', '&#46;'], $email);
echo '<a href="mailto:'.$email.'">'.$obfuscated_email.'</a>';
?>