PHP以星号隐藏用户名手机号码和邮箱实例

一款简单实用的PHP以星号隐藏用户名手机号码和邮箱实例,将用户的一些文字信息隐藏一部分用星号代替,以便于保护用户隐私。

隐藏函数:

function hideStar($str) { //用户名、邮箱、手机账号中间字符串以*隐藏 
    if (strpos($str, '@')) { 
        $email_array = explode("@", $str); 
        $prevfix = (strlen($email_array[0]) < 4) ? "" : substr($str, 0, 3); //邮箱前缀 
        $count = 0; 
        $str = preg_replace('/([\d\w+_-]{0,100})@/', '***@', $str, -1, $count); 
        $rs = $prevfix . $str; 
    } else { 
        $pattern = '/(1[3458]{1}[0-9])[0-9]{4}([0-9]{4})/i'; 
        if (preg_match($pattern, $str)) { 
            $rs = preg_replace($pattern, '$1****$2', $str); // substr_replace($name,'****',3,4); 
        } else { 
            $rs = substr($str, 0, 3) . "***" . substr($str, -1); 
        } 
    } 
    return $rs; 
}

测试数据:

<?php 
$account = "sucaihuo.com"; 
$email = "123456789@qq.com"; 
$phone = "13800000000"; 
?>

以星号*显示实例:

<table width="100%"> 
    <tr> 
        <td>账号</td> 
        <td>邮箱</td> 
        <td>手机</td> 
    </tr> 
    <tr> 
        <td><?php echo $account;?></td> 
        <td><?php echo $email;?></td> 
        <td><?php echo $phone;?></td> 
    </tr> 
    <tr> 
        <td><?php echo hideStar($account);?></td> 
        <td><?php echo hideStar($email);?></td> 
        <td><?php echo hideStar($phone);?></td> 
    </tr> 
</table>

本文转自:https://www.sucaihuo.com/php/548.html 转载请注明出处!
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值