페이지

2015년 11월 5일 목요일

asterisk

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("example@gmail.com");
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.