Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $email = preg_replace('/(?:^|@).K|.[^@]*$(*SKIP)(*F)|.(?=.*?.)/', '*', $linha['cli_email']);
- $email = preg_replace('/(?:^|.@).K|..[^@]*$(*SKIP)(*F)|.(?=.*?.)/', '*', $linha['cli_email']);
- <?php
- ini_set('display_errors', 1);
- $email="victor@gmail.com";
- preg_match_all('/(?<=b[a-z])[a-z]+(?=.@)|(?<=@.)[a-z]+(?=..)/',$email,$matches);
- foreach($matches[0] as $key => $value)
- {
- $email=str_replace($value, getStars(strlen($value)), $email);
- }
- echo $email;
- function getStars($length)
- {
- $string="";
- for($x=0;$x<$length;$x++)
- {
- $string.="*";
- }
- return $string;
- }
- <?php
- function starmid($str) {
- switch (strlen($str)) {
- case 0: return false;
- case 1: return $str;
- case 2: return $str[0] . "*";
- default: return $str[0] . str_repeat("*", strlen($str) - 2) . substr($str, -1);
- }
- }
- function hideemail($email) {
- if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
- return false;
- }
- list($u, $d) = explode("@", $email);
- $d = explode(".", $d);
- $tld = array_pop($d);
- $d = implode(".", $d);
- return starmid($u) . "@" . starmid($d) . ".$tld";
- }
- $emails = [
- "victor@gmail.com",
- "v@example.com",
- "victor@g.com",
- "victor@host.example.com",
- "victor+foo@gmail.com",
- "invalid@",
- ];
- foreach ($emails as $email) {
- echo hideemail($email) . "n";
- }
Add Comment
Please, Sign In to add comment