I found this nice email protector script from css-tricks.com (link)
Here is the code:
<?php
function php_split_js_make_email($phpemail)
{
$pieces = explode("@", $phpemail);
echo '
<script type="text/javascript">
var a = "<a href=\'mailto:";
var b = "' . $pieces[0] . '";
var c = "' . $pieces[1] .'";
var d = "\' class=\'email\'>";
var e = "</a>";
document.write(a+b+"@"+c+d+b+"@"+c+e);
</script>
<noscript>Please enable JavaScript to view emails</noscript>
';
}
?>
Usage
<?php php_split_js_make_email("youremail@here.com"); ?>
Now I would like to know how secure this code is today, since this post is more than a year old now…
Thank you
The script is only secure if the robot sniffing your page for email addresses doesn’t execute the JavaScript.
On my personal site, I embed my email address as an image and use an online form to send mail instead of a mailto link.