Skip to content

Instantly share code, notes, and snippets.

@hansspiess
Created August 5, 2012 14:21
Show Gist options
  • Save hansspiess/3265096 to your computer and use it in GitHub Desktop.
Save hansspiess/3265096 to your computer and use it in GitHub Desktop.
Php: Mask email address in string, using preg_replace_callback
<?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);
}
?>
@mshoperi
Copy link

create_function() is now deprecated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment