Log in / Register
Login to your account
Remember Me
Create an account
Fields marked with an asterisk (*) are required.
Reload Captcha
 
Ideas in practice

ARENAM

Web dewelopment

Простой пример маскировки части емайла звездочками на PHP

	public static function maskEmail($email) {
		$mail_parts   = explode("@", $email);
		$domain_parts = explode('.', $mail_parts[1]);

		$mail_parts[0]   = self::mask($mail_parts[0], 1, 1);
		$domain_parts[0] = self::mask($domain_parts[0], 1, 1);
		$mail_parts[1]   = implode('.', $domain_parts);
		$masked          = implode("@", $mail_parts);
		return $masked;
	}
	private static function mask($str, $first, $last) {
		$len = strlen($str);
		$toShow = $first + $last;
		return substr($str, 0, $len <= $toShow ? 0 : $first).str_repeat("*", $len - ($len <= $toShow ? 0 : $toShow)).substr($str, $len - $last, $len <= $toShow ? 0 : $last);
	}

Теперь вызовим функцию maskEmail($email) и у нас получится:

a@a.com => *@*.com
ab@ab.com => **@**.com
abc@abc.com => a*c@a*c.com
abcd@abcd.com => a**d@a**d.com
abcde@abcde.com => a***e@a***e.com

Недостаточно прав для комментирования

Purchase guarantees

Secured payment
100% Secure Payments with bank сards, YooMoney, QIWI and others.
Official invoice
You'll receive an official invoice instantly in accordance with law 54-F3.
Instant download
Instant download after payment.