PHP实现手机号码中间四位数替换成星号*

小天天天天    PHP    757 次    2022-12-07 10:48:53


示例:

字符串截取法

/**
 * 中间加密 字符串截取法
 */
public static function encryptTel($tel) {
    $new_tel = substr($tel, 0, 3).'****'.substr($tel, 7);
    return $new_tel;
}

替换字符串:

/**
 * 中间加密 替换字符串的子串
 */
public static function encryptTel($tel) {
    $new_tel = substr_replace($tel, '****', 3, 4);
    return $new_tel;
}

正则:

/**
 * 中间加密 用正则
 */
public static function encryptTel($tel) {
    $new_tel = preg_replace('/(\d{3})\d{4}(\d{4})/', '$1****$2', $tel);
    return $new_tel;
}

以上便是PHP实现手机号码中间四位数替换成星号*的方法,请大家参考。


如果你觉得本篇文章对您有帮助,请打赏作者

上一篇: utf8和utf8mb4的区别

下一篇: 快速了解什么是JWT(JSON Web Token)

最新评论

暂无评论

热门文章

最新评论

网站数据

网站文章数:481

今日UV/PV/IP:20/24/20

昨日UV/PV/IP:11/14 /10

TOP