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

示例:

字符串截取法

/**
 * 中间加密 字符串截取法
 */
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;
}

温馨提示: 本文最后更新于2024-12-31 20:59:23,某些文章具有时效性,若有错误或已失效,请在下方 留言或联系 蚂蚁官方
© 版权声明
THE END
喜欢就支持一下吧
点赞14赞赏 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容