当前位置:首页 > PHP > 正文内容

php转换文本编码,php字符编码转换,php编码转换

高老师6年前 (2020-05-04)PHP1943

整理一个自己用的编码转换方法,不需要知道原字符串的编码,只需要传入字符串,和你想要转换的编码。

/**
 * 编码转换
 * @param string $char
 * @param string $coding
 * @return string
 */
public static function convert_char($char, $coding = 'UTF-8')
{
    $encode_arr = ['UTF-8', 'ASCII', 'GBK', 'GB2312', 'BIG5', 'JIS', 'eucjp-win', 'sjis-win', 'EUC-JP'];
    $encoded = mb_detect_encoding($char, $encode_arr);
    if ($encoded)
    {
        $char = mb_convert_encoding($char, $coding, $encoded);
    }
    return $char;
}

扫描二维码推送至手机访问。

版权声明:本文由高久峰个人博客发布,如需转载请注明出处。

本文链接:https://blog.20230611.cn/post/136.html

分享给朋友:

“ php转换文本编码,php字符编码转换,php编码转换” 的相关文章

PHP中$this和self的区别

PHP中$this和self的区别

<?php //对比$this和self   /*  * $this更倾向于对象本身  *   */   class  Par{     public   ...

PHP高并发下数据库值更新的问题

PHP高并发下数据库值更新的问题

(1).创建数据库test ,创建表shop(字段id,total),商品id是1,商品总数10    (2).PHP模拟购买,商品数量大于0才能购买<?php //连接数据库 $con=mysqli_connect("192.168.2.18...

 php监听事件,php触发事件

php监听事件,php触发事件

逛公众号文章看到文章"php实现事件监听与触发的方法,你用过吗?",我就好奇了,php又不是asp.net的webform,哪里来的服务端事件监听。于是学习了一波。先看下监听类:class Event {     /** &nbs...

php  RabbitMQ消息队列

php RabbitMQ消息队列

(1).config.php 配置文件<?php /**  * RabbitMQ_Config  */ $config = [     'host' => ...

php new class

php new class

<?php $member = new class {     public function getInfo()     {    ...

PHP Startup: Unable to load dynamic library 'C:\php\ext\php_curl.dll找不到指定的模块

PHP Startup: Unable to load dynamic library 'C:\php\ext\php_curl.dll找不到指定的模块

最近在编写windows php多线程的东西,从官网下载了PHP的线程安全版,尝试开启curl扩展extension=php_curl.dllphp -m 却提示 PHP Startup: Unable to load dynamic library 'C:\php\ext\php_curl...