php将汉字转ascii的方法:首先创建一个php示例文件;然后通过封装好的“public function strtoascii($str){}”方法将汉字转为ascii即可。
php入门到就业线上直播课:进入学习
Apipost = Postman + Swagger + Mock + Jmeter 超好用的API调试工具:点击使用
推荐:《PHP视频教程》
直接使用吧,函数就在下面,自己封装的,亲测正确无误
将字符串(中文同样实用)转为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);}
登录后复制
以上就是php如何将汉字转ascii的详细内容,更多请关注php中文网其它相关文章!