Skip to content

Instantly share code, notes, and snippets.

@lutzissler
Last active June 10, 2016 06:36
Show Gist options
  • Save lutzissler/a9330b4fb8c087ba0a35997ab2cb7db5 to your computer and use it in GitHub Desktop.
Save lutzissler/a9330b4fb8c087ba0a35997ab2cb7db5 to your computer and use it in GitHub Desktop.
ROT13 encode all mailto: links in the HTML.
function encode_mailto($s) {
return preg_replace_callback('#<a href="mailto:(.+?)">(.*?)</a>#', function ($matches) {
return '<a href="#" onclick="location.href=\'' . str_rot13('mailto:' . $matches[1]) . '\'.replace(/[a-zA-Z]/g,function(c){return String.fromCharCode((c<=\'Z\'?90:122)>=(c=c.charCodeAt(0)+13)?c:c-26);});return false">' . str_replace('@', ' [&#8203;at&#8203;] ', $matches[2]) . '</a>';
}, $s);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment