-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmask_email.php
56 lines (40 loc) · 1011 Bytes
/
mask_email.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
function mask_email( $email ) {
/*
Author: Fed
Simple way of masking emails
*/
$char_shown = 3;
$mail_parts = explode("@", $email);
$username = $mail_parts[0];
$len = strlen( $username );
if( $len <= $char_shown ){
return implode("@", $mail_parts );
}
//Logic: show asterisk in middle, but also show the last character before @
$mail_parts[0] = substr( $username, 0 , $char_shown )
. str_repeat("*", $len - $char_shown - 1 )
. substr( $username, $len - $char_shown + 2 , 1 )
;
return implode("@", $mail_parts );
}
//Sample usage and results
$emails = array(
);
foreach( $emails as $email ){
echo " <b>$email</b> ";
echo '<br />';
$em = mask_email ( $email );
echo $em ;
echo '<br />';
echo '<hr />';
}