We all get unnecessary amounts of spam, so here’s a simple way of stopping search engine spiders and spammers from scanning your website pages and finding your email address.
Each character in HTML has an ordinal value, which is it’s ASCII value in the range 0 – 255. The first 31 are reserved for tab, shift, carriage return, end of line etc, but every other value will display a unique ASCII character. For example, the letter "A" has ASCII value 65. Don’t believe me? If you’re on a Windows PC, hold down Alt and press 65 on the keypad. Release the Alt key and "A" will be displayed. Nice.
To display the character in HTML, simply write A and your browser will output A. With this in mind, we can write a simple function that takes your email address, and converts it into a list of ASCII values. The HTML won't look too good, but your browser won't care.
function convertToOrd($str) {
$ordStr="";
for ($i=0; $i<strlen($str); $i++) $ordStr.="".ord($str[$i]).";";
return $ordStr;
}
function hideEmail($email_address, $subject) {
$link="mailto:".$email_address;
if ($subject!="") $link.="?Subject=".$subject;
$link=convertToOrd($link);
$email_address=convertToOrd($email_address);
$str="<a href='".$link."' title='Contact Us'>".$email_address."</a>";
return $str;
}
print "If you are having problems, please contact me at ";
print hideEmail('myemail@mydomain.com', 'Website Contact');
?>
>> Posted in Websites at 15:03, and viewed 7,292 times
Next article: Creating Multipart Emails in PHP (15 June 2009)
Next Websites article: Email Address Format Function (24 November 2009)
Add your comments