在PHP中字符截取函数substr只能截取全英文才不会出现乱码如果里面有中文肯定是无法截取的,下面小编来给大家介绍两个兼容各类gbk,utf-8编码字符串截取函数,实例代码如下:
- function CsubStrPro($str, $start, $length, $charset = "utf-8", $suffix = false)
- {
- if (function_exists ( "mb_substr" ))
- return mb_substr ( $str, $start, $length, $charset );
- $re ['utf-8'] = "/[x01-x7f]|[xc2-xdf][x80-xbf]|[xe0-xef][x80-xbf]{2}|[xf0-xff][x80-xbf]{3}/";
- $re ['gb2312'] = "/[x01-x7f]|[xb0-xf7][xa0-xfe]/";
- $re ['gbk'] = "/[x01-x7f]|[x81-xfe][x40-xfe]/";
- $re ['big5'] = "/[x01-x7f]|[x81-xfe]([x40-x7e]|xa1-xfe])/";
- preg_match_all ( $re [$charset], $str, $match );
- $slice = join ( "", array_slice ( $match [0], $start, $length ) );
- if ($suffix)
- return $slice . "…";
- return $slice;
- }
实例代码二:
- function subString_UTF8($str, $start, $lenth)
- {
- $len = strlen($str);
- $r = array();
- $n = 0;
- $m = 0;
- for($i = 0; $i < $len; $i++) {
- $x = substr($str, $i, 1);
- $a = base_convert(ord($x), 10, 2);
- $a = substr('00000000'.$a, -8);
- if ($n < $start){
- if (substr($a, 0, 1) == 0) {
- }elseif (substr($a, 0, 3) == 110) {
- $i += 1;
- }elseif (substr($a, 0, 4) == 1110) {
- $i += 2;
- }
- $n++;
- }else{
- if (substr($a, 0, 1) == 0) {
- $r[ ] = substr($str, $i, 1);
- }elseif (substr($a, 0, 3) == 110) {
- $r[ ] = substr($str, $i, 2);
- $i += 1;
- }elseif (substr($a, 0, 4) == 1110) {
- $r[ ] = substr($str, $i, 3);
- $i += 2;
- }else{
- $r[ ] = '';
- }
- if (++$m >= $lenth){
- break;
- }
- }
- }
- return $r;
- } // End subString_UTF8;
- // End String
由于此函数返回的是一个数组,因此要配合join函数来显示字符串:join('',subString_UTF8($str, $start, $lenth));,在页面显示的时候还可以在此语句后面连一个"…"
波比源码 – 精品源码模版分享 | www.bobi11.com
1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长!
2. 分享目的仅供大家学习和交流,您必须在下载后24小时内删除!
3. 不得使用于非法商业用途,不得违反国家法律。否则后果自负!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系管理员处理!
6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需!
7. 本站源码并不保证全部能正常使用,仅供有技术基础的人学习研究,请谨慎下载
8. 如遇到加密压缩包,请使用WINRAR解压,如遇到无法解压的请联系管理员!
波比源码 » PHP字符截取函数,兼容各类gbk,utf-8编码
波比源码 » PHP字符截取函数,兼容各类gbk,utf-8编码
buy levaquin order levaquin 250mg pills
lamotrigine 50mg pill buy prazosin pills retin tablet
accutane 20mg us order azithromycin pills order zithromax 250mg
cheap arimidex 1 mg where to buy viagra pills generic viagra
cost doxycycline 100mg vardenafil 10mg sale purchase furosemide
purchase zyban online oral strattera 10mg brand seroquel 50mg
oral avlosulfon 100mg aceon 4mg brand buy perindopril 4mg generic
buy cialis 10mg pill buy anafranil 25mg online cheap buy anafranil 50mg pill
custom written papers money slots money games
order cialis pill cost cialis 40mg clopidogrel 150mg generic
order zyloprim 100mg without prescription allopurinol 100mg brand buy zetia online cheap
colchicine 0.5mg cost colchicine cost free spins no deposit canada
ranitidine 150mg oral oral meloxicam buy generic celebrex
buy desyrel sale order suhagra 100mg sale sildenafil canada
sildenafil 50mg for sale viagra without prescription purchase tadalafil for sale
casino free spins no deposit modafinil 100mg brand provigil 100mg ca
oral tadalafil 20mg order indomethacin 75mg generic buy indocin generic
order clarithromycin 500mg generic order meclizine pill antivert 25mg for sale
buy tiotropium bromide online cheap minocycline online order terazosin brand
buy pioglitazone 30mg generic sildenafil 25mg for sale sildenafil 100mg ca
poker online cash best online blackjack online slot machines real money
global poker online canadian pharmacies online order research papers
write paper online buy azulfidine 500mg generic buy azulfidine 500mg generic
doxycycline 200mg brand buy clindamycin cleocin for sale
olmesartan pills buy depakote divalproex 250mg ca
order acetazolamide generic imuran 25mg generic azathioprine 25mg ca
cost lanoxin digoxin order online purchase molnupiravir online cheap
buy coreg without prescription order ditropan sale amitriptyline 10mg usa
priligy price domperidone brand buy domperidone 10mg for sale
order alendronate for sale buy motrin online cheap ibuprofen 400mg brand
buy indomethacin 75mg capsule order generic tamsulosin 0.2mg generic cenforce 50mg
order generic nortriptyline 25 mg buy paroxetine online cheap purchase paxil
doxycycline 100mg oral purchase doxycycline for sale methylprednisolone 4mg without prescription
oral ropinirole order requip generic labetalol 100 mg ca
cheap provigil 200mg buy promethazine online promethazine usa
ivermectin purchase erectile dysfunction drug oral deltasone 5mg
order absorica order amoxil 250mg generic azithromycin medication
albuterol order amoxiclav for sale purchase amoxiclav pill
cheap prednisolone generic generic prednisolone order furosemide for sale
buy modafinil 100mg without prescription modafinil order online purchase lopressor online
order oxybutynin 5mg without prescription oxybutynin over the counter oxcarbazepine brand
omnicef uk order cefdinir 300mg protonix over the counter
oral dapsone 100mg avlosulfon cost order tenormin pill
order generic medex warfarin 5mg generic generic allopurinol
order zyrtec online order cetirizine 5mg generic zoloft oral
buy cenforce sale cenforce 100mg cost buy generic glucophage 1000mg
buy cheap atorvastatin viagra australia oral viagra
order femara 2.5 mg sale letrozole drug viagra 100mg pill
order tadalafil 10mg sale real tadalafil for sale over the counter ed pills that work
buy amoxicillin generic amoxil for sale generic prednisolone
isotretinoin 20mg without prescription order zithromax 500mg online cheap zithromax 500mg canada
order gabapentin without prescription order lasix 100mg generic cheap doxycycline
order clomid 100mg sale buy vardenafil tablets buy plaquenil 400mg online
synthroid 100mcg pills oral clomid 100mg cheap vardenafil 10mg
order metformin without prescription buy glycomet 500mg online cheap order amlodipine 5mg online cheap
zestril 2.5mg cost omeprazole 20mg brand metoprolol 50mg generic
pregabalin for sale online purchase lyrica pills order priligy pill
order generic methotrexate 5mg order coumadin 5mg pill reglan online buy
xenical without prescription buy zovirax 800mg online buy zyloprim 100mg
buy generic cozaar online cost nexium 40mg order topiramate 200mg pills
sumatriptan where to buy order generic dutasteride dutasteride medication
order zantac 300mg order meloxicam without prescription oral celecoxib 100mg
clopidogrel 150mg sale buy generic ketoconazole online order ketoconazole 200mg
purchase duloxetine for sale order duloxetine 20mg generic piracetam
nateglinide 120mg brand buy generic atacand buy atacand 16mg for sale
how to get simvastatin without a prescription valtrex usa viagra pills 100mg
carbamazepine tablet cheap lincocin buy lincocin 500mg pill
buy cialis 5mg tadalafil fast delivery usa order generic sildenafil 100mg
estrace 1mg tablet buy cheap generic lamotrigine buy minipress 1mg online cheap
buy mebendazole cheap buy tadalafil 10mg online cheap buy tadalis 10mg
buy avanafil without prescription order diclofenac 100mg without prescription diclofenac order
order nolvadex order ceftin 500mg online order cefuroxime 250mg
buy indocin no prescription buy suprax generic order suprax for sale
amoxicillin sale order arimidex for sale buy clarithromycin online
careprost allergy nasal spray buy generic methocarbamol over the counter purchase desyrel without prescription
order generic clonidine 0.1 mg tiotropium bromide over the counter buy generic tiotropium bromide 9mcg
sildenafil 50mg drug sildenafil for sale sildenafil 150mg for sale
order leflunomide 10mg sale sulfasalazine 500mg without prescription order sulfasalazine for sale
cialis coupon walmart usa pharmacy cialis order cialis for sale
altace ca ramipril 5mg over the counter buy arcoxia 60mg sale
levitra cost where to buy tizanidine without a prescription buy plaquenil 400mg generic
buy mesalamine paypal order irbesartan 300mg pills order avapro 300mg generic
buy generic coreg cenforce 50mg uk aralen cost
buy digoxin generic buy digoxin without prescription buy molnunat 200 mg generic
order naproxen 250mg pill buy lansoprazole cheap prevacid tablet
buy singulair pills for sale dapsone 100mg generic dapsone 100 mg pill
purchase nifedipine online fexofenadine 180mg brand allegra 180mg over the counter