Last active
February 2, 2018 14:30
-
-
Save lemmon/109e27e81f7d76390531a4d608f00c41 to your computer and use it in GitHub Desktop.
encode/decode email address in HTML
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
PHP 5.2 and IE 10 tested.