PHP 手机号中间4位加密

Posted 认真生活、快乐工作 - 马云

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP 手机号中间4位加密相关的知识,希望对你有一定的参考价值。

    /**
     * 中间加密 字符串截取法
     */
    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 手机号中间4位加密的主要内容,如果未能解决你的问题,请参考以下文章