//How to encode a file when testing if UTF8$str= ' Chinese a character 1 characters '; Echo strlen($str).‘ <br> ';// -EchoMb_strlen ($str, ' UTF8 '). ' <br> ';//6EchoMb_strlen ($str, ' GBK '). ' <br> ';//8EchoMb_strlen ($str, ' gb2312 '). ' <br> ';//Ten
/** * Only keep the string first and last characters, hide the middle with * instead of (two characters only show the only one) * @param string $user _name name * @return String formatted name*/functionSubstr_cut ($user _name){ $strlen= Mb_strlen ($user _name, ' Utf-8 '); $firstStr= Mb_substr ($user _name, 0, 1, ' Utf-8 '); $lastStr= Mb_substr ($user _name,-1, 1, ' Utf-8 '); return $strlen= = 2?$firstStr.str_repeat(' * ', Mb_strlen ($user _name, ' Utf-8 ')-1):$firstStr.str_repeat("*",$strlen-2).$lastStr;}
PHP displays only the name and end characters, hides the middle characters and replaces them with *