Skip to content

Instantly share code, notes, and snippets.

@l4ci
Created January 9, 2018 10:11
Show Gist options
  • Select an option

  • Save l4ci/de3c8bb270cfabc4c0d6b0472ce6fa3a to your computer and use it in GitHub Desktop.

Select an option

Save l4ci/de3c8bb270cfabc4c0d6b0472ce6fa3a to your computer and use it in GitHub Desktop.
Encrypts an email via rot13 encryption
<?php
/**
* Encrypts an email w/out mailto link via rot13 encryption
* decrypts it via javascript
* @param string $email Email
* @param boolean $mailto Wrap in <a href='mailto:'></a>
* @return string Safe Email
*/
function safeMail($email,$mailto=true){
$e = str_rot13($email);
if ($mailto){
return '<script type="text/javascript">
document.write(\'<n uers="znvygb:'.$e.'">'.$e.'</n>\'.replace(/[a-zA-Z]/g, function(c){return String.fromCharCode((c<="Z"?90:122)>=(c=c.charCodeAt(0)+13)?c:c-26);}));
</script>';
}else{
return '<script type="text/javascript">
document.write(\''.$e.'\'.replace(/[a-zA-Z]/g, function(c){return String.fromCharCode((c<="Z"?90:122)>=(c=c.charCodeAt(0)+13)?c:c-26);}));
</script>';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment