php如何隐藏电子邮件地址的一部分?

i currently have this:

    $value = preg_replace('@hotmail.com', '***********', $value);
    $value = preg_replace('yahoo.com', '***********', $value);
    $value = preg_replace('outlook.com', '***********', $value);
    $value = preg_replace('mailinator.com', '***********', $value);
    $value = preg_replace('live.com', '***********', $value);
    $value = preg_replace('live.nl', '***********', $value);

but how can i show e email adress like this: juliankuit******** ? email is: juliankuitert@hotmail.com

and without having to replace all the email providers like hotmail.com with *'s

thanks in advance!

echo preg_replace('/(?<=.).(?=.*@)/u','*','TestEmail@Google.com');

Will return

T********@Google.com

My PhP is too rusty to put code example, but here's the logic I would use :

  1. find @ symbol index in string 2)
  2. truncate string to X characters , X being the number found on step 1 minus a certain number of characters (up to you to decide)
  3. Add a certain amount of * to the string you obtained in step 2

Note that during step 2, if X <= 0, then the whole string should be replace by * characters

I'm using this function

function maskEmail($email, $minLength = 3, $maxLength = 10, $mask = "***") {
   $atPos = strrpos($email, "@");
   $name = substr($email, 0, $atPos);
   $len = strlen($name);
   $domain = substr($email, $atPos);

   if (($len / 2) < $maxLength) $maxLength = ($len / 2);

  $shortenedEmail = (($len > $minLength) ? substr($name, 0, $maxLength) : "");
  return  "{$shortenedEmail}{$mask}{$domain}";
 }

This an example

echo maskEmail('abcdfghi@example.com'); // abcd***@example.com

Sometimes its good to show the last character too.

I will suggest you keep things simple. Maybe something like this is simple enough https://github.com/fedmich/PHP_Codes/blob/master/mask_email.php

Masks an email to show first 3 characters and then the last character before the @ sign

ABCDEFZ@gmail.com becomes A*****Z@gmail.com

function mask_email( $email ) {
    /*
    Author: Fed
    Simple way of masking emails
    */

    $char_shown = 3;

    $mail_parts = explode("@", $email);
    $username = $mail_parts[0];
    $len = strlen( $username );

    if( $len <= $char_shown ){
        return implode("@", $mail_parts );  
    }

    //Logic: show asterisk in middle, but also show the last character before @
    $mail_parts[0] = substr( $username, 0 , $char_shown )
        . str_repeat("*", $len - $char_shown - 1 )
        . substr( $username, $len - $char_shown + 2 , 1  )
        ;

    return implode("@", $mail_parts );
}