/ Published in: PHP
This is a little function that encodes an email and hides it from spammers.
It creates a few lines of javascript code that displays the email on a website with a mailto link, custom text link and you can even add a class or something as an attribute to the tag.
Expand |
Embed | Plain Text
function encode_email($email='[email protected]', $linkText='Contact Us', $attrs ='class="emailencoder"' ) { // remplazar aroba y puntos $email = str_split($email, 5); $linkText = str_split($linkText, 5); $part1 = '<a href="ma'; $part2 = 'ilto:'; $part3 = '" '. $attrs .' >'; $part4 = '</a>'; // generamos el Javascript $encoded = '<script type="text/javascript">'; $encoded .= "document.write('$part1');"; $encoded .= "document.write('$part2');"; foreach($email as $e) { $encoded .= "document.write('$e');"; } $encoded .= "document.write('$part3');"; foreach($linkText as $l) { $encoded .= "document.write('$l');"; } $encoded .= "document.write('$part4');"; $encoded .= '</script>'; return $encoded; }
You need to login to post a comment.
