我举个例子,比如说:$str = "13760721151"; 我要把这个手机号变成: 1376****1151 ;就隐藏中间的大约三分之一的内容怎么用PHP实现。感激不尽。

解决方案 »

  1.   


    <?php
    $str = "13760721151"; 
    echo substr_replace($str,"***",4,3);
    ?>
      

  2.   

    内置函数没有
    $str = "13760721151";  
    //1376****1151
    echo substr($str, 0, 4).'****'.substr($str, strlen($str) - 4);
      

  3.   

    function hiden_mymoblie($str){
    if(empty($str)) return $str;
    $string = $str;
    $pattern = "/(1\d{1,2})\d\d(\d{0,3})/";
    $replacement = "\$1****\$3";
    return preg_replace($pattern, $replacement, $string);
    }