Obfuscate e-mail link
- July 23rd, 2007
- php, Snippet-library
This function allows it to hide the email address within a link so it is not this easy to be grabbed by spiders.
This function allows it to hide the email address within a link so it is not this easy to be grabbed by spiders. <code class="prettyprint"> function mailto($address, $text) { $address_encode = ''; for ($x=0; $x < strlen($address); $x++) { if(preg_match('!\w!',$address[$x])) { $address_encode .= '%' . bin2hex($address[$x]); } else { $address_encode .= $address[$x]; } } $text_encode = ''; for ($x=0; $x < strlen($text); $x++) { $text_encode .= '&#x' . bin2hex($text[$x]).';'; } $mailto = "mailto:"; return '<a href="'.$mailto.$address_encode.'">'.$text_encode.''; } echo mailto('my@mail.com','Mail me'); </code>
















Submit your comment