Created
August 5, 2012 14:21
-
-
Save hansspiess/3265096 to your computer and use it in GitHub Desktop.
Php: Mask email address in string, using preg_replace_callback
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
<?php | |
function hs_mailreplace($str) { | |
return preg_replace_callback ('^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})^', | |
create_function ( | |
'$str', | |
'for ($i = 0; $i < strlen($str[0]); $i++) { | |
$result .= "&#" . ord(substr($str[0], $i, 1)) . ";"; | |
}; | |
return $result;' | |
), | |
$str); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
create_function()
is now deprecated.