开发技术学习 »
编程开发 » php mb_detect_encoding函数,开启mb_detect_encoding,检测字符编码
php mb_detect_encoding函数,开启mb_detect_encoding,检测字符编码
今天在调试博客发现出现一个错误,内容标题。
call to undefined function mb_convert_encoding in。。。
在网上找了一些解决方法,基本上都是windows下的php解决方法。
在php.ini中开启mbstring函数库:去掉extension=php_mbstring.dll前面的分号;
但是我的系统是linux所以终于找到解决方法。特此记录。
首先安装 php-mbstring库文件:
yum install php-mbstring
之后,修改/etc/php.ini文件,在里面加一句
extension=mbstring.so
保存后重启httpd服务。
service httpd restart
//
检测字符编码mb_detect_encoding()函数
文章提供这款mb_detect_encoding函数是一款可以检测你使用的字符串是什么编码,然后返回字符串编码字符,下面是一个简单应用实例。
[php]
function asciitog($brand)
{
$cha=mb_detect_encoding($brand);
if($cha=='utf-8')
{
$brand2 = iconv($cha,"gb2312",$brand);
}
$cha2=mb_detect_encoding($brand2);
if($cha2!='ascii'){
$brand=$brand2;
}
return $brand;
}
[/php]
mb_detect_encoding
语法
string mb_detect_encoding ( string $str [, mixed $encoding_list = mb_detect_order() [, bool $strict = false ]] )
说明
mb_detect_encoding 用来检测字符串所使用编码,并返回相对应编码字符串!
您可能还会对这些文章感兴趣!
- 关于O2O持久战,九问创业者(3167 +)
- centos cpu查看,linux进程查看,查看所有进程,停止进程(3419 +)
- nscd错误:bind(5, {sa_family=AF_FILE, path="/var/(6643 +)
- mysql数据表描述文档模板下载,mysql结构设计(3931 +)
- JS判断来路域名(2969 +)
- php定界符(2984 +)
- js检测访问是手机或者PC端(3442 +)
- wordpress判断是否首页,wordpress判断是否首页的if(is_home())不(2657 +)
- js prototype使用实例,prototype详解,js prototype用法(2593 +)
- js跳出循环的方法区别(break,continue,return)(4725 +)