fork download
  1. <?php
  2. $emails = array(
  3. 'verysecretemail@gmail.com',
  4. 'example@example.org',
  5. 'someotheremail@example.com',
  6. );
  7.  
  8. function obfuscate_email($email) {
  9. $at_position = strpos($email, '@');
  10. $chop = rand(1, $at_position - 1);
  11. $mask = str_repeat('*', rand(4, 8));
  12.  
  13. $partial_address = substr($email, 0, $chop);
  14. $domain = substr($email, $at_position);
  15. return $partial_address . $mask . $domain;
  16. }
  17.  
  18. foreach($emails as $email) {
  19. var_dump(obfuscate_email($email));
  20. }
Success #stdin #stdout 0.02s 13112KB
stdin
Standard input is empty
stdout
string(19) "ve*******@gmail.com"
string(24) "examp*******@example.org"
string(32) "someotherema********@example.com"