Skip to content

Instantly share code, notes, and snippets.

@CoryDuncan
Last active December 16, 2015 02:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CoryDuncan/5366177 to your computer and use it in GitHub Desktop.
Save CoryDuncan/5366177 to your computer and use it in GitHub Desktop.
PHP function to obfuscate an email address
/**
* Obfuscate an email address
*
* @param string {$email} email address
* @param boolean {$isLink} create mailto link or not
*
* @return string
*
*/
function obfuscate_email( $email, $isLink = FALSE ) {
$ret = '';
$len = strlen( $email );
for ( $i = 0; $i < $len; $i++ ) {
$ret .= '&#'.ord( $email[ $i ] ).';';
}
if ( $isLink ) {
$ret = '<a href="mailto:'.$ret.'">'.$ret.'</a>';
}
return $ret;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment