I
I
Ilkhomjon Matazimov2020-04-14 14:10:49
PHP
Ilkhomjon Matazimov, 2020-04-14 14:10:49

How to encrypt first 3 letters in php?

Good day.
I have this code:

echo json_encode("Почта вашего запрашиваемого аккаунта: ".$_SESSION['email_fetch'].". Отправить код восстанновления на почту?");


Here, I need to encrypt this " ". It is desirable to mark in the middle with asterisks, like this: "tee***[email protected]" $_SESSION['email_fetch']

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2020-04-14
@mr_qpdb

function hideEmail(string $email, int $length = 3, string $symbol = '*'): string
{
    $emailData = explode('@', $email);
    $username  = str_split($emailData[0], $length);
    $middle    = floor(count($username) / 2);

    $username[$middle] = str_repeat($symbol, $length);

    return implode('', $username) . '@' . $emailData[1];
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question