This function takes any string and converts it into an ASCII encoded character. I wrote this function recently to help prevent email harvesting spambots from collecting email addresses from a client’s site.
This method is far from robust, and will only deter fairly rudimentary spambots from collecting email addresses from your site. If you are using a CMS like Drupal, I would highly recommend using a module such as Invisimail (http://drupal.org/project/invisimail) or SpamSpan filter (http://drupal.org/project/spamspan) which use more effective methods such as javascript encryption and things like that. Those 2 modules also integrate with Email Field (http://drupal.org/project/email) to make your life even easier.
<?php
function encode_ascii($email) {
$num = strlen($email);
for ($i = 0; $i < $num; $i++) {
$char = substr($email, $i, 1);
$encoded[] = '&#'. ord($char) .';';
}
return implode($encoded);
}
// to use this function, simple pass your email address string into it.
$email = ‘[email protected]’;
print ‘Email Address: ‘. encode_ascii($email);
?>
The result should not be obvious (because your browser should automatically handle decoding the ASCII characters), but if you look at the source of the page, you should see something like this: