Hello Folks,
I'm trying to use php to hide email addresses from harvesters, and have found the following code -
<?php
function hide_email($email) {
$character_set = '+-.0123456789@ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz';
$key = str_shuffle($character_set);
$cipher_text = '';
$id = 'e'.rand(1,999999999);
for ($i=0;$i<strlen($email);$i+=1) $cipher_text.= $key[strpos($character_set,$email[$i])];
$script = 'var a="'.$key.'";var b=a.split("").sort().join("");var c="'.$cipher_text.'";var d="";';
$script.= 'for(var e=0;e<c.length;e++)d+=b.charAt(a.indexOf(c.charAt(e)));';
$script.= 'document.getElementById("'.$id.'").innerHTML="<a href=\\"mailto:"+d+"\\">"+d+"</a>"';
$script = "eval(\"".str_replace(array("\\",'"'),array("\\\\",'\"'), $script)."\")";
$script = '<script type="text/javascript">/*<![CDATA[*/'.$script.'/*]]>*/</script>';
return '<span id="'.$id.'">[javascript protected email address]</span>'.$script;
}
?>
<p>Some interesting text goes here, followed by email - </p>
<?php echo hide_email('info@mydomain.com'); ?>
This works well, but I'm having trouble editing the last line so that instead of the address being shown, the page displays "Email Us" or "Contact Us". I have tried the following line -
<a href="mailto:<?php echo hide_email('info@mydomain.com'); ?>">Email Us</a>
But the page then displays the following -
[javascript protected email address]">Email Us
The whole line is a clickable link, and although it brings up the email client, it doesn't fill in the "to" field in the email.
Can anyone see where I'm going wrong with this?
Hope someone can advise.