php explode() 函数定义与用法汇总(2021)
2022-12-02 09:01:16
117
{{single.collect_count}}

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中文网其它相关文章!

回帖
全部回帖({{commentCount}})
{{item.user.nickname}} {{item.user.group_title}} {{item.friend_time}}
{{item.content}}
{{item.comment_content_show ? '取消' : '回复'}} 删除
回帖
{{reply.user.nickname}} {{reply.user.group_title}} {{reply.friend_time}}
{{reply.content}}
{{reply.comment_content_show ? '取消' : '回复'}} 删除
回帖
收起
没有更多啦~
{{commentLoading ? '加载中...' : '查看更多评论'}}