Last active
December 16, 2015 02:59
-
-
Save CoryDuncan/5366177 to your computer and use it in GitHub Desktop.
PHP function to obfuscate an email address
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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