您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

php 中文怎么转换ascii码

2024/8/26 3:07:07发布31次查看
php中文转换ascii码的方法:首先设置当前php文件环境为utf-8;然后通过“public function strtoascii($str){...}”将中文转换为ascii码即可。
本文操作环境:windows7系统、php7.1版,dell g3电脑
php 中文怎么转换ascii码?
php将字符串转为ascii,php将中文汉字字符串转为ascii,以及互转
直接使用吧,函数就在下面,自己封装的,亲测正确无误
a:将字符串(中文同样实用)转为ascii(注意:我默认当前我们的php文件环境是utf-8,如果是gbk的话mb_convert_encoding操作就不需要)
public 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); }
b:将ascii转为字符串(中文同样实用)(注意:我默认当前我们的php文件环境是utf-8,如果是gbk的话mb_convert_encoding操作就不需要)
public function 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'); }
推荐学习:《php视频教程》
以上就是php 中文怎么转换ascii码的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product