如何使用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; }