在php中利用mb_detect_encoding可以判断给我们的字符是那个类型的编码了,从而我们就可以利用inconv进行字符转换了,下面给大家介绍几个例子.
例子,利用mb_detect_encoding()判断字符是否为uft-8编码,代码如下:
- $encode = mb_detect_encoding($q, array('GB2312','GBK','UTF-8'));
- echo $encode."<br/>";
- if($encode=="GB2312")
- {
- $q = iconv("GBK","UTF-8",$q);
- }
- else if($encode=="GBK")
- {
- $q = iconv("GBK","UTF-8",$q);
- }
- else if($encode=="EUC-CN")
- {
- $q = iconv("GBK","UTF-8",$q);
- }
- else//CP936
- {
- //$q = iconv("GB2312","UTF-8",$q);
- }
可是 mb_detect_encoding 存在一个硬伤,经常出现判断不准确的情况,或许这样就可以解决,代码如下:
- // 使用 iconv 转换并判断是否等值,效率不高
- function is_utf8 ($str) {
- if ($str === iconv('UTF-8', 'UTF-8//IGNORE', $str)) {
- return 'UTF-8';
- }
- }
- // 多种编码的情况
- function detect_encoding ($str) {
- foreach (array('GBK', 'UTF-8') as $v) {
- if ($str === iconv($v, $v . '//IGNORE', $str)) {
- return $v;
- }
- }
- }
通过以上方式得到字符串编码信息后,就可以利用 iconv 或 mb_convert_encoding 来转换编码了.
问题:可是当 $keytitle = '%D0%BE%C6%AC'; 时,检测结果却是UTF-8,这其实不算是bug,我们不应当过于依赖mb_detect_encoding,当字符串较短时,检测结果产生偏差的可能性很大.
解决方法,代码如下:
$encode = mb_detect_encoding($keytitle, array('ASCII','GB2312′,'GBK’,'UTF-8');
波比源码 – 精品源码模版分享 | www.bobi11.com
1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长!
2. 分享目的仅供大家学习和交流,您必须在下载后24小时内删除!
3. 不得使用于非法商业用途,不得违反国家法律。否则后果自负!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系管理员处理!
6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需!
7. 本站源码并不保证全部能正常使用,仅供有技术基础的人学习研究,请谨慎下载
8. 如遇到加密压缩包,请使用WINRAR解压,如遇到无法解压的请联系管理员!
波比源码 » php mb_detect_encoding判断字符串编码方法
波比源码 » php mb_detect_encoding判断字符串编码方法
buy levaquin 250mg sale levaquin buy online
buy generic avodart 0.5mg order celecoxib 100mg without prescription zofran 8mg without prescription
buy aldactone 25mg without prescription fluconazole 100mg price diflucan 100mg uk
cheap ampicillin order cephalexin 250mg sale purchase erythromycin pills
buy sildenafil generic bimatoprost pills buy robaxin 500mg generic
buy generic suhagra 100mg suhagra generic order estradiol 2mg pill
order lamictal 50mg pills prazosin drug tretinoin gel drug
tadalafil price avanafil 100mg us order diclofenac pills
generic cialis 40mg cialis 20 price order sildenafil for sale
buy arimidex generic generic viagra paypal viagra next day
order prednisone 10mg pills where to buy cialis buy viagra pills
isotretinoin sale order azithromycin generic ivermectin order online
altace 5mg tablet astelin 10ml oral purchase azelastine online cheap
terazosin 5mg cheap hytrin online buy azulfidine sale
alendronate generic purchase panadol online pepcid 40mg without prescription
tacrolimus 1mg tablet order requip sale urso oral
buy imdur 40mg online telmisartan price order micardis 20mg generic
order zyban generic zyrtec 10mg cheap quetiapine order online
buy imuran 100mcg for sale pantoprazole 40mg sale viagra 50mg over the counter
oral cialis 20mg prozac 20mg cheap cheap sildenafil pills
order medroxyprogesterone without prescription purchase medroxyprogesterone without prescription cyproheptadine medication
order generic provigil purchase provigil for sale buy stromectol pills
goodrx cialis buy sildenafil 50mg purchase viagra without prescription
chloroquine 250mg pill baricitinib 4mg canada order olumiant 4mg online
brand sporanox 100 mg prometrium 100mg uk tindamax online buy
buy generic olanzapine order diovan 80mg generic buy generic diovan
norvasc cheap tadalafil canada pfizer cialis
buy clozapine 100mg for sale clozapine 50mg brand buy dexamethasone 0,0,5 mg without prescription
prilosec online order prilosec 20mg for sale free online slot machines
buy linezolid 600 mg pills buy zyvox 600mg without prescription black jack
essay writing sites best website for writing essays real money casino app
write essays for money sildenafil ca buy viagra 50mg online
clomid tablet online casino for real cash poker game
dapoxetine pill order dapoxetine 30mg online buy synthroid sale
cialis 20mg brand viagra cheap sildenafil 150mg for sale
order methotrexate 5mg generic coumadin 2mg without prescription reglan 20mg brand
motilium 10mg oral purchase motilium generic order cyclobenzaprine 15mg online
losartan 50mg uk topiramate usa order generic topamax 200mg
baclofen online order buy generic zanaflex oral toradol
imitrex price brand imitrex 25mg purchase dutasteride pills
gloperba usa colchicine order free online blackjack
order ranitidine 150mg celecoxib 200mg generic order celecoxib pill
order tamsulosin without prescription brand aldactone 100mg order spironolactone
order cialis without prescription order ampicillin without prescription order cipro 500mg
simvastatin uk simvastatin 10mg for sale finasteride 5mg cheap
order sildalis without prescription generic lamictal order lamotrigine 50mg generic
azithromycin 500mg price oral gabapentin 600mg buy gabapentin 800mg pill
casino slots free play poker online free no sign up purchase provigil online
buy lasix 40mg doxycycline 200mg cheap buy generic hydroxychloroquine
deltasone 5mg us brand deltasone 20mg vermox online
order tretinoin online tadalis over the counter oral avana 200mg
tadacip usa purchase diclofenac indomethacin 50mg cost
terbinafine pills buy generic lamisil order trimox 500mg for sale
buy pioglitazone 30mg for sale cheap actos sildenafil 200mg
stromectol pills canada order avlosulfon 100 mg without prescription avlosulfon 100 mg uk
no deposit free spins slots games free gambling addiction
lanoxin 250 mg us generic molnupiravir 200 mg molnunat 200 mg without prescription
Great post thank you. Hello Administ . Metropol Halı Karaca Halı Öztekin ve Selçuklu Halı Cami Halısı ve Cami Halıları Türkiye’nin En Büyük Cami Halısı Fabrikasıyız…
oral nortriptyline purchase pamelor sale paxil 10mg oral
Good info. Lucky me I reach on your website by accident, I bookmarked it. Metropol Halı Karaca Halı Öztekin ve Selçuklu Halı Cami Halısı ve Cami Halıları Türkiye’nin En Büyük Cami Halısı Fabrikasıyız…
buy doxycycline 100mg pill methylprednisolone us methylprednisolonee online
Great post thank you. Hello Administ . Metropol Halı Karaca Halı Öztekin ve Selçuklu Halı Cami Halısı ve Cami Halıları Türkiye’nin En Büyük Cami Halısı Fabrikasıyız…
tadalafil tablet order clopidogrel trimox 250mg cost
generic cialis 10mg buy ed medications natural pills for erectile dysfunction
Thank you for content. Area rugs and online home decor store. Hello Administ . Onwin , Onwin Giriş , Onwin Güncel Giriş , Onwin Yeni Adres , onwin
deltasone 40mg over the counter cost accutane amoxil for sale online