Skip to content

Instantly share code, notes, and snippets.

@lemmon
Last active February 2, 2018 14:30
Show Gist options
  • Save lemmon/109e27e81f7d76390531a4d608f00c41 to your computer and use it in GitHub Desktop.
Save lemmon/109e27e81f7d76390531a4d608f00c41 to your computer and use it in GitHub Desktop.
encode/decode email address in HTML
var elements = document.querySelectorAll('[data-mailto]');
for (var i = elements.length - 1; i >= 0; i--) {
var el = elements[i];
var email = '';
for (var j = el.children.length - 1; j >= 0; j--) {
if (el.children[j].style.display !== 'none') {
email = el.children[j].innerText + email;
}
}
el.innerHTML = email;
el.href = 'mailto:' + email;
}
function email($email)
{
$res = '';
$len = strlen($email);
for ($i=0; $i < $len; $i++) {
$res .= sprintf('<span style="display: none;">%s</span><span>%s</span>', chr(rand(97, 122)), $email[$i]);
}
return $res;
}
@lemmon
Copy link
Author

lemmon commented Feb 2, 2018

PHP 5.2 and IE 10 tested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment