Ver Mensaje Individual
  #4 (permalink)  
Antiguo 22/08/2014, 15:22
Avatar de kspr
kspr
 
Fecha de Ingreso: agosto-2011
Ubicación: Ecuador
Mensajes: 43
Antigüedad: 12 años, 8 meses
Puntos: 7
Respuesta: Como reemplazar partes de un mail por asteriscos (***)

acabo de crear un codigo, me parecio interesante una funcion que haga eso, te dejo el codigo aca:

Código PHP:
Ver original
  1. /* censor mail by kspr :PP */
  2.  
  3. function censor_email($email = ''){
  4.  
  5. // TODO: check email
  6.  
  7. // email string
  8. $email = $email;
  9.  
  10. // search important email parts
  11. preg_match('~([^@]+)@([^\.]+)((\.[^$]+)+)~', $email, $email_parts);
  12.  
  13. // get prefix email
  14.  
  15. // get 40% of email
  16. $percent = 40; // change it or not :)
  17.  
  18. // calcule percent
  19. $prefix_percent = (strlen($email_parts[1]) * $percent) / 100;
  20.  
  21. // set prefix email
  22. $prefix_email = substr($email, 0, $prefix_percent) . str_repeat('*', strlen($email_parts[1])-($prefix_percent-1));
  23.  
  24. // set suffix
  25.  
  26. $suffix_email = str_repeat('*', strlen($email_parts[2])) . $email_parts[3];
  27.  
  28. // set new email string
  29. $new_email = $prefix_email . '@' . $suffix_email;
  30.  
  31. return $new_email;
  32.  
  33. }
  34.  
  35.   censor_email('[email protected]'),
  36.   censor_email('[email protected]'),
  37.   censor_email('[email protected]'),
  38.   censor_email('[email protected]')
  39. ));

retorna:

Código HTML:
Ver original
  1. array(4) {
  2.   [0]=>
  3.   string(25) "ksp******@***********.com"
  4.   [1]=>
  5.   string(11) "k***@**.net"
  6.   [2]=>
  7.   string(25) "jonat*********@******.net"
  8.   [3]=>
  9.   string(38) "whiitewhiit*****************@*****.com"
  10. }