Guest User

Untitled

a guest
Mar 4th, 2018
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. $email = preg_replace('/(?:^|@).K|.[^@]*$(*SKIP)(*F)|.(?=.*?.)/', '*', $linha['cli_email']);
  2.  
  3. $email = preg_replace('/(?:^|.@).K|..[^@]*$(*SKIP)(*F)|.(?=.*?.)/', '*', $linha['cli_email']);
  4.  
  5. <?php
  6.  
  7. ini_set('display_errors', 1);
  8. $email="victor@gmail.com";
  9. preg_match_all('/(?<=b[a-z])[a-z]+(?=.@)|(?<=@.)[a-z]+(?=..)/',$email,$matches);
  10. foreach($matches[0] as $key => $value)
  11. {
  12. $email=str_replace($value, getStars(strlen($value)), $email);
  13. }
  14. echo $email;
  15. function getStars($length)
  16. {
  17. $string="";
  18. for($x=0;$x<$length;$x++)
  19. {
  20. $string.="*";
  21. }
  22. return $string;
  23. }
  24.  
  25. <?php
  26. function starmid($str) {
  27. switch (strlen($str)) {
  28. case 0: return false;
  29. case 1: return $str;
  30. case 2: return $str[0] . "*";
  31. default: return $str[0] . str_repeat("*", strlen($str) - 2) . substr($str, -1);
  32. }
  33. }
  34. function hideemail($email) {
  35. if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
  36. return false;
  37. }
  38. list($u, $d) = explode("@", $email);
  39. $d = explode(".", $d);
  40. $tld = array_pop($d);
  41. $d = implode(".", $d);
  42. return starmid($u) . "@" . starmid($d) . ".$tld";
  43. }
  44.  
  45. $emails = [
  46. "victor@gmail.com",
  47. "v@example.com",
  48. "victor@g.com",
  49. "victor@host.example.com",
  50. "victor+foo@gmail.com",
  51. "invalid@",
  52. ];
  53.  
  54. foreach ($emails as $email) {
  55. echo hideemail($email) . "n";
  56. }
Add Comment
Please, Sign In to add comment