Skip to content

Instantly share code, notes, and snippets.

@yuhisern7
Forked from jasonmcleod/email-masking.js
Created October 14, 2019 09:26
Show Gist options
  • Save yuhisern7/1c6f99dee27ec6ab9f6ce77d294349fa to your computer and use it in GitHub Desktop.
Save yuhisern7/1c6f99dee27ec6ab9f6ce77d294349fa to your computer and use it in GitHub Desktop.
/* Not sure if this has any effect against email scraping bots but it's an idea.
It just outputs the string as an array of character codes, then restores it
real characters after the page loads. With javascript disabled we fail. :( */
// PHP function ///////////////////////////////////
function mask($str) {
$mask = "";
for($c=0;$c<strlen($str);$c++) {
$mask .= "" . ord($str[$c]) . ",";
}
return "<span class='mask'>" . $mask . "</span>";
}
// end of PHP function ////////////////////////////
// jQuery function ////////////////////////////////
$(".mask").each(function() {
c = $(this).text().split(",");
v="";
for(l in c) {
v+=(String.fromCharCode(c[l]));
}
$(this).html(v);
});
// end of jQuery function /////////////////////////
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment