header(‘Content-type:text/html;charset=utf-8‘); function cutstr($str) { #计算$str的字符个数 preg_match_all("/./u", $str, $len); $strlen = (int) count($len[0]); #计算中间位置开始转* $start = ceil($strlen / 2); $start = ceil($start / 2); #计算结束的字符长度 $forlen = $strlen - $start; $string = ‘‘; #将字符串里面的字分割成一个数组 for($i=0; $i < $strlen; $i ++) { if( $i <= $start || $i >= $forlen ) { $string .= $len[0][$i]; } else { $string .= ‘*‘; } } return $string; }
$str = ‘[email protected]‘;
echo cutstr( $str ); exit;
时间: 2024-10-29 02:56:45