php中將ascii轉(zhuǎn)字符串的方法:默認(rèn)當(dāng)前的php文件環(huán)境是【utf-8】,如果是gbk的話將【mb_convert_encoding】省略即可,代碼為【function asciitostr($sacii)】。
php中將ascii轉(zhuǎn)字符串的方法:
將字符串(支持中文)轉(zhuǎn)為ascii
注意:默認(rèn)當(dāng)前的php文件環(huán)境是utf-8,如果是gbk的話mb_convert_encoding可省略。
function strtoascii($str){$str=mb_convert_encoding($str,'gb2312');$change_after='';for($i=0;$i<strlen($str);$i ){$temp_str=dechex(ord($str[$i]));$change_after.=$temp_str[1].$temp_str[0];}return strtoupper($change_after);}//strtoasciifunction asciitostr($sacii){$asc_arr= str_split(strtolower($sacii),2);$str='';for($i=0;$i<count($asc_arr);$i ){$str.=chr(hexdec($asc_arr[$i][1].$asc_arr[$i][0]));}return mb_convert_encoding($str,'utf-8','gb2312');}相關(guān)學(xué)習(xí)推薦:php編程從入門到精通