You'll need a specific function for each. For mails:
function hide_mail($email) {
$mail_segments = explode("@", $email);
$mail_segments[0] = str_repeat("*", strlen($mail_segments[0]));
return implode("@", $mail_segments);
}
echo hide_mail("[email protected]");
For phone numbers
function hide_phone($phone) {
return substr($phone, 0, -4) . "****";
}
echo hide_phone("1234567890");
And see? Not a single regular expression used. These functions don't check for validity though. You'll need to determine what kind of string is what, and call the appropriate function.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…