Answer the question
In order to leave comments, you need to log in
How to mask email using regular expression?
I need [email protected]
to receive from u***[email protected]***l.com.ua
while I receive u***[email protected]***l.c***m.ua
.
I found the code, but it's not exactly what I need:
function maskEmail($email)
{
$email = preg_replace('/(?<=[\w]{1})[\w-\._\+%]+(?=[\w]{1}@)/', '***', $email);
return preg_replace('/(?<=[\w]{1})[\w-\+%]+(?=[\w]{1}[.])/', '***', $email);
}
Answer the question
In order to leave comments, you need to log in
Try instead of regular expressions to use regular functions (not strong in php, therefore pseudocode)
функция замаскировать_адрес(адрес) {
пусть [имя, домен] = адрес.разделить('@')
пусть новое_имя = имя[0] + повторить('*', имя.длина-1)
пусть новый_домен = повторить('*', домен.длина-2) + домен.подстрока(домен.длина-2, 2)
вернуть новое_имя + '@' + новый_домен
}
no need to use a code whose meaning you do not understand - learn regular expressions
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question