确定字符编码是否为UTF-8格式 函数 (1)
来源:互联网 发布:淘宝订单贷款逾期 编辑:程序博客网 时间:2024/06/05 16:56
function phpdigVerifyUTF8($str) {
// verify if a given string is encoded in valid utf-8
if ($str === mb_convert_encoding(mb_convert_encoding($str, "UTF-32", "UTF-8"), "UTF-8", "UTF-32")) {
return $str;
}
else {
return false;
}
}
其中用的的关键函数是 mb_convert_encoding 的解释:
mb_convert_encoding
(PHP 4 >= 4.0.6, PHP 5)
mb_convert_encoding -- Convert character encodingDescription
string mb_convert_encoding ( string str, string to_encoding [, mixed from_encoding] )mb_convert_encoding() converts character encoding of string str from from_encoding to to_encoding.
str : String to be converted.
from_encoding is specified by character code name before conversion. it can be array or string - comma separated enumerated list. If it is not specified, the internal encoding will be used.
例子 1. mb_convert_encoding() example
/* Convert internal character encoding to SJIS */
$str = mb_convert_encoding($str, "SJIS");
/* Convert EUC-JP to UTF-7 */
$str = mb_convert_encoding($str, "UTF-7", "EUC-JP");
/* Auto detect encoding from JIS, eucjp-win, sjis-win, then convert str to UCS-2LE */
$str = mb_convert_encoding($str, "UCS-2LE", "JIS, eucjp-win, sjis-win");
/* "auto" is expanded to "ASCII,JIS,UTF-8,EUC-JP,SJIS" */
$str = mb_convert_encoding($str, "EUC-JP", "auto");
?>
- 确定字符编码是否为UTF-8格式 函数 (1)
- PHP判断编码是否为utf-8 函数
- 判断字符串是否为 utf-8 编码
- eclipse设置编码格式为utf-8
- 改变cmd编码格式为utf-8
- myeclipse配置编码格式为utf-8
- eclipse指定编码格式为UTF-8
- Eclipse 设置编码格式为UTF-8
- studio 设置编码格式为 UTF-8
- mysql定义字符为utf-8格式
- 项目修改为UTF-8字符编码
- PHP判断字符编码类型是否为UTF-8型
- 字符编码转换 各种函数 UTF格式转换、
- PHP中检测文件是否为UTF-8编码的函数
- utf-8编码格式
- utf-8编码格式
- 字符编码格式小结(ASCII/Unicode/UTF-8)
- 字符编码格式小结(ASCII/Unicode/UTF-8)
- 盛云网络-IP地址转城市数据库
- Linux多线程程序设计,(网络上流传的一道题)
- 字符转换时出现的诡异问题
- [Fedora core 7.0]使用CDlinux制作usb os
- ubuntu,新的开始,纪念帖
- 确定字符编码是否为UTF-8格式 函数 (1)
- 【Fedora core 7.0】增加Neoshine Linux 3.0软件
- 技术文章,链接收藏.
- 不能使用 mb_strlen 函数的问题
- VS 2005 快捷键
- 实现 目标另存为 的效果
- 服务端口大全+注解
- 从最底层实现汉字输出,一个中文启动界面的实现方法
- malloc()