• 技术文章 >后端开发 >PHP问题

    php中文编码转换问题

    coldplay.xixicoldplay.xixi2020-08-06 10:42:04原创896

    php中文编码转换的方法:1、使用iconv函数,代码为【string iconv (string $in_, string $out_, string $str)】;2、使用【mb_convert_encoding】函数。

    php入门到就业线上直播课:进入学习

    php中文编码转换的方法:

    一、iconv

    string iconv ( string $in_charset , string $out_charset , string $str )

    第一个参数:内容原的编码

    第二个参数:目标编码

    第三个参数:要转的字符串

    $filename='我爱你中国';
    $filename = iconv('gbk','utf-8',$filename);

    解析:把$filename从gbk转换为utf8

    二、mb_convert_encoding

    string mb_convert_encoding ( string $str , string $to_encoding [, mixed $from_encoding ] )

    第一个参数:要处理的字符串

    第二个参数:目标编码

    第三个参数:内容原编码

    $filename='我爱你中国';
    $filename = mb_convert_encoding($filename,'GBK','UTF-8');

    解析:把$filename从utf8转换为gbk

    三、mb_detect_encoding查看字符编码

    $filename='我爱你中国';
    $encode = mb_detect_encoding($filename, array("ASCII","UTF-8","GB2312","GBK","BIG5"));
    echo $encode;die;

    在这里插入图片描述

    e39334fc8485b4640422b3fb951c226.png

    相关学习推荐:php编程(视频)

    以上就是php中文编码转换问题的详细内容,更多请关注php中文网其它相关文章!

    声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。

    前端(VUE)零基础到就业课程:点击学习

    清晰的学习路线+老师随时辅导答疑

    自己动手写 PHP MVC 框架:点击学习

    快速了解MVC架构、了解框架底层运行原理

    专题推荐:php 中文编码转换
    上一篇:php 保存文件名乱码怎么办 下一篇:自己动手写 PHP MVC 框架(40节精讲/巨细/新人进阶必看)

    相关文章推荐

    • ❤️‍🔥共22门课程,总价3725元,会员免费学• ❤️‍🔥接口自动化测试不想写代码?• php 中文编码小技巧你要知道?• php中json_encode中文编码的问题• php中uft-8中文编码乱码怎么办?• php如何转换中文编码
    1/1

    PHP中文网