- function utf8_gb2312($str, $default = 'gb2312')
- {
- $str = preg_replace("/[x01-x7f]+/", "", $str);
- if (emptyempty($str)) return $default;
- $preg = array(
- "gb2312" => "/^([xa1-xf7][xa0-xfe])+$/", //正则判断是否是gb2312
- "utf-8" => "/^[x{4e00}-x{9fa5}]+$/u", //正则判断是否是汉字(utf8编码的条件了),这个范围实际上已经包含了繁体中文字了
- );
- if ($default == 'gb2312') {
- $option = 'utf-8';
- } else {
- $option = 'gb2312';
- }
- if (!preg_match($preg[$default], $str)) {
- return $option;
- }
- $str = @iconv($default, $option, $str);
- //不能转成 $option, 说明原来的不是 $default
- if (emptyempty($str)) {
- return $option;
- }
默认编码是gb2312,而且我统计了一下,90%的情况下都是gb2312,所以,我的检测函数不能出现本来是gb2312的,结果被检测出utf8. 基本思路是:
1. 把所有的ascii去掉,如果全部都是ascii,那么就是gb2312。
2. 假设这个字符串是gb2312,用一个正则检查它是否是真的gb2312,如果不是,那么就是utf-8
3. 然后,用iconv 把字符串转换成utf8,如果转换不成功,那么原来可能不是真正的一个gb2312编码的字符(用正则匹配我已经尽量精确,但是,gb2312的编码不是连续的,还是会有空洞),那么最后的编码就是utf-8.
4. 否则就是gb2312 编码:加入这样的检查功能后,在1000个关键字里面,就出现了1个乱码,比以前的近100个关键字乱码少了很多。
波比源码 – 精品源码模版分享 | www.bobi11.com
1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长!
2. 分享目的仅供大家学习和交流,您必须在下载后24小时内删除!
3. 不得使用于非法商业用途,不得违反国家法律。否则后果自负!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系管理员处理!
6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需!
7. 本站源码并不保证全部能正常使用,仅供有技术基础的人学习研究,请谨慎下载
8. 如遇到加密压缩包,请使用WINRAR解压,如遇到无法解压的请联系管理员!
波比源码 » php 检测字符编码代码
波比源码 » php 检测字符编码代码
buy levaquin 250mg without prescription order levofloxacin
avodart medication order dutasteride generic buy zofran pill
ampicillin online buy ampicillin cheap erythromycin us
fildena 50mg ca fildena 50mg uk generic methocarbamol 500mg
sildenafil 50mg canada buy estrace for sale estrace 1mg without prescription
tadalafil drug tadalafil 10mg pill diclofenac 100mg cheap
accutane 20mg generic azithromycin 500mg usa zithromax 500mg drug
indomethacin order online brand indomethacin 50mg order trimox without prescription
anastrozole medication natural viagra for women sildenafil 100mg us
generique tadalafil 5mg acheter du cialis sildenafil generique en pharmacie
prednisone pills prednisone buy online purchase viagra generic
cialis 20mg fГјr frauen sildenafil kaufen viagra 50mg kaufen
modafinil 200mg usa order provigil 200mg for sale cheap diamox 250 mg
generic doxycycline doxycycline 200mg cheap buy furosemide pill
buy terazosin pills hytrin 1mg tablet buy generic sulfasalazine 500 mg
order alendronate 70mg without prescription brand motrin 400mg famotidine 20mg for sale
buy olmesartan 20mg online order olmesartan 10mg pill cost diamox
prograf for sale online urso uk order urso 150mg without prescription
bupropion us cheap bupropion brand seroquel
buy molnunat 200 mg sale buy naproxen 250mg sale order lansoprazole 15mg without prescription
salbutamol 100mcg brand order imuran 100 mcg pills female viagra pill
brand cialis 5mg Get cialis viagra canada
tadalafil 20mg oral cialis 10mg uk order symmetrel 100 mg pill
cheap naltrexone 50mg order aripiprazole 30mg online cheap buy abilify 30mg generic
avlosulfon 100 mg over the counter aceon 8mg usa cheap aceon
provera over the counter brand periactin 4 mg periactin 4mg oral
fluvoxamine order purchase fluvoxamine generic buy glucotrol 5mg pill
purchase piracetam pills viagra next day delivery buy sildenafil 50mg pills
purchase lasix online cheap order hydroxychloroquine 200mg generic hydroxychloroquine 400mg cheap
buy cialis tablets tadalafil generic name clomipramine order online
cheap aralen buy cenforce 100mg pills generic olumiant
sporanox 100 mg oral order tindamax 300mg online order tindamax 500mg pills
zyprexa 10mg pills olanzapine brand generic valsartan
buy amlodipine online cheap viagra price cialis mail order usa
buy clozaril generic cheap clozapine 50mg order dexamethasone 0,5 mg generic
sildenafil tablets sildenafil 100mg ca lisinopril 2.5mg for sale
purchase zyvox online casinos usa free blackjack
order omeprazole 10mg generic play poker online free blackjack game
order metoprolol 50mg online cheap atenolol 50mg for sale vardenafil uk
buy essay now write my paper for me online roulette wheel
generic vardenafil 20mg order lyrica 150mg for sale methylprednisolone 16mg online
write my term paper help with assignments uk viagra sildenafil 150mg
generic clomid 50mg clomiphene 50mg ca casino online gambling
tadalafil 40mg pills viagra brand order sildenafil 50mg generic
buy priligy online cheap misoprostol 200mcg sale synthroid uk
order cialis 10mg online buy plavix online cheap order plavix 150mg sale
methotrexate 5mg uk methotrexate 10mg ca buy reglan without prescription
cost domperidone order tetracycline sale buy flexeril 15mg
cost losartan 25mg nexium 20mg for sale buy topiramate for sale
order imitrex 25mg online order imitrex 50mg sale buy dutasteride generic
gloperba ca play casino slots online casino slots no download
zantac sale purchase celebrex pills celecoxib 200mg over the counter
best online gambling sites free poker online no deposit free spins
oral tadalafil 40mg cost acillin purchase ciprofloxacin generic
purchase zocor pill valacyclovir 1000mg brand order proscar without prescription
order cialis 40mg sale cialis coupons oral viagra
cheap ceftin 500mg purchase careprost without prescription buy generic methocarbamol 500mg
free spins no deposit usa win real money online casino for free cialis next day
custom dissertation services essay edit ivermectin 8 mg