天天看點

php ascii轉字元,php中如何将ascii轉字元串?

php中将ascii轉字元串的方法:預設目前的php檔案環境是【UTF-8】,如果是GBK的話将【mb_convert_encoding】省略即可,代碼為【function asciitostr($sacii)】。

php ascii轉字元,php中如何将ascii轉字元串?

php中将ascii轉字元串的方法:

将字元串(支援中文)轉為ascii

注意:預設目前的php檔案環境是UTF-8,如果是GBK的話mb_convert_encoding可省略。function strtoascii($str){

$str=mb_convert_encoding($str,'GB2312');

$change_after='';

for($i=0;$i

$temp_str=dechex(ord($str[$i]));

$change_after.=$temp_str[1].$temp_str[0];

}

return strtoupper($change_after);

}//strtoascii

function asciitostr($sacii){

$asc_arr= str_split(strtolower($sacii),2);

$str='';

for($i=0;$i

$str.=chr(hexdec($asc_arr[$i][1].$asc_arr[$i][0]));

}

return mb_convert_encoding($str,'UTF-8','GB2312');

}