Skip to content

Instantly share code, notes, and snippets.

@nr1q
Last active August 6, 2016 01:47
Show Gist options
  • Save nr1q/b4e9885413d7abda4def85ada1911eda to your computer and use it in GitHub Desktop.
Save nr1q/b4e9885413d7abda4def85ada1911eda to your computer and use it in GitHub Desktop.
Mail obfuscator
<?php
/**
* Mail obfuscation
* Original function as in @see except for the $text argument
* @see http://www.maurits.vdschee.nl/php_hide_email/
*/
function hide_email($email, $text = '') {
$character_set = '+-.0123456789@ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz';
$key = str_shuffle($character_set);
$cipher_text = '';
$id = 'e'.rand(1,999999999);
for ( $i = 0; $i < strlen($email); $i += 1 )
$cipher_text.= $key[ strpos($character_set, $email[$i]) ];
$script = 'var a="'.$key.'";var b=a.split("").sort().join("");var c="'.$cipher_text.'";var d="";';
$script.= 'for(var e=0;e<c.length;e++)d+=b.charAt(a.indexOf(c.charAt(e)));';
$script.= 'document.getElementById("'.$id.'").innerHTML="<a href=\\"mailto:"+d+"\\">'.(empty($text)?'"+d+"':$text).'</a>"';
$script = "eval(\"".str_replace(array("\\",'"'),array("\\\\",'\"'), $script)."\")";
$script = '<script type="text/javascript">/*<![CDATA[*/'.$script.'/*]]>*/</script>';
return '<span id="'.$id.'">[javascript protected email address]</span>'.$script;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment