php 检测中文编码,php – 如何检测哪种类型的中文编码有文本文件?

这可能适合您的需求(但我真的不能说).设置locale和utf8_decode,并使用mb_check_encoding而不是mt_detect_encoding似乎给出了一些有用的输出..

// some text from http://chinesenotes.com/chinese_text_l10n.php

// have tried both as string and content loaded from a file

$chinese = '譧躆 礛簼繰 剆坲姏 潧 騔鯬 跠 瘱瘵瘲 忁曨曣 蛃袚觙';

$chinese=utf8_decode($chinese);

$chinese_encodings ='EUC-CN,HZ,GBK,CP936,GB18030,EUC-TW,BIG5,CP950,BIG5-HKSCS,BIG5-HKSCS:2004,BIG5-HKSCS:2001,BIG5-HKSCS:1999,ISO-2022-CN,ISO-2022-CN-EXT';

$encodings = explode(',',$chinese_encodings);

//set chinese locale

setlocale(LC_CTYPE, 'Chinese');

foreach($encodings as $encoding) {

if (@mb_check_encoding($chinese, $encoding)) {

echo 'The string seems to be compatible with '.$encoding.'
';

} else {

echo 'Not compatible with '.$encoding.'
';

}

}

输出

The string seems to be compatible with EUC-CN

The string seems to be compatible with HZ

The string seems to be compatible with GBK

The string seems to be compatible with CP936

Not compatible with GB18030

The string seems to be compatible with EUC-TW

The string seems to be compatible with BIG5

The string seems to be compatible with CP950

Not compatible with BIG5-HKSCS

Not compatible with BIG5-HKSCS:2004

Not compatible with BIG5-HKSCS:2001

Not compatible with BIG5-HKSCS:1999

Not compatible with ISO-2022-CN

Not compatible with ISO-2022-CN-EXT

这是完全猜测.现在它至少似乎认识到了一些中国编码.如果是完全垃圾则删除.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值