PHP中文乱码一般是字符集问题,编码主要有下面几个问题。
一.首先是PHP网页的编码
1. php文件本身的编码与网页的编码应匹配
a. 如果欲使用gb2312编码,那么php要输出头:header(“Content-Type: text/html; charset=gb2312"),静态页面添加<meta http-equiv="Content-Type" content="text/html; charset=gb2312">,所有文件的编码格式为ANSI,可用记事本打开,另存为选择编码为ANSI,覆盖源文件。
b. 如果欲使用utf-8编码,那么php要输出头:header(“Content-Type: text/html; charset=utf-8"),静态页面添加<meta http-equiv="Content-Type" content="text/html; charset=utf-8">,所有文件的编码格式为utf-8。保存为utf-8可能会有点麻烦,一般utf-8文件开头会有BOM,如果使用session就会出问题,可用editplus来保存,在editplus中,工具->参数选择->文件->UTF-8签名,选择总是删除,再保存就可以去掉BOM信息了。
2. php本身不是Unicode的,所有substr之类的函数得改成mb_substr(需要装mbstring扩展);或者用iconv转码。
二.PHP与Mysql的数据交互
PHP与数据库的编码应一致
1. 修改mysql配置文件my.ini或my.cnf,mysql最好用utf8编码
[mysql]
default-character-set=utf8
[mysqld]
default-character-set=utf8
default-storage-engine=MyISAM
在[mysqld]下加入:
default-collation=utf8_bin
init_connect=’SET NAMES utf8′
2. 在需要做数据库操作的php程序前加mysql_query("set names ‘编码’");,编码和php编码一致,如果php编码是gb2312那mysql编码就是gb2312,如果是utf-8那mysql编码就是utf8,这样插入或检索数据时就不会出现乱码了
三.PHP与操作系统相关
Windows和Linux的编码是不一样的,在Windows环境下,调用PHP的函数时参数如果是utf-8编码会出现错误,比如move_uploaded_file()、filesize()、readfile()等,这些函数在处理上传、下载时经常会用到,调用时可能会出现下面的错误:
Warning: move_uploaded_file()[function.move-uploaded-file]:failed to open stream: Invalid argument in …
Warning: move_uploaded_file()[function.move-uploaded-file]:Unable to move ” to ” in …
Warning: filesize() [function.filesize]: stat failed for … in …
Warning: readfile() [function.readfile]: failed to open stream: Invalid argument in ..
在Linux环境下用gb2312编码虽然不会出现这些错误,但保存后的文件名出现乱码导致无法读取文件,这时可先将参数转换成操作系统识别的编码,编码转换可用mb_convert_encoding(字符串,新编码,原编码)或iconv(原编码,新编码,字符串),这样处理后保存的文件名就不会出现乱码,也可以正常读取文件,实现中文名称文件的上传、下载。
其实还有更好的解决方法,彻底与系统脱离,也就不用考虑系统是何编码。可以生成一个只有字母和数字的序列作为文件名,而将原来带有中文的名字保存在数据库中,这样调用move_uploaded_file()就不会出现问题,下载的时候只需将文件名改为原来带有中文的名字。实现下载的代码如下
header("Pragma: public");
header("Expires: 0");
header("Cache-Component: must-revalidate, post-check=0, pre-check=0");
header("Content-type: $file_type");
header("Content-Length: $file_size");
header("Content-Disposition: attachment; filename="$file_name"");
header("Content-Transfer-Encoding: binary");
readfile($file_path);
$file_type是文件的类型,$file_name是原来的名字,$file_path是保存在服务上文件的地址。
波比源码 » 完美解决PHP中文乱码的问题
levofloxacin pills purchase levofloxacin without prescription
order generic avodart 0.5mg ondansetron for sale online ondansetron over the counter
aldactone uk buy diflucan 200mg sale diflucan 200mg usa
order ampicillin 250mg online cheap buy cephalexin 125mg for sale erythromycin over the counter
buy sildenafil 50mg sildenafil oral buy robaxin generic
suhagra medication buy estrace generic order estrace 1mg online cheap
order lamotrigine order vermox 100mg online buy tretinoin cream online
order tadalis online cheap order diclofenac 50mg pills buy voltaren 100mg online cheap
arimidex 1mg drug buy anastrozole 1mg without prescription brand viagra pills
cialis 40mg sans ordonnance en france pharmacie en ligne viagra vrai viagra 100mg prix
tadalafil 20mg fГјr frauen viagra 50mg generika sildenafil 200mg generika
order provigil generic provigil 100mg pill acetazolamide tablet
order doxycycline 200mg sale buy clomid 100mg online order lasix 40mg pills
catapres 0.1mg over the counter order tiotropium bromide 9mcg generic generic spiriva
buy buspar pills buy cordarone 100mg buy ditropan 5mg pills
cheap fosamax 35mg alendronate oral famotidine uk
buy olmesartan 20mg generic buy divalproex diamox online
cost tacrolimus 5mg order labetalol 100 mg online purchase ursodiol sale
order zyban sale bupropion for sale order generic seroquel
salbutamol order pantoprazole pills viagra mail order us
cialis 10mg brand order fluoxetine 20mg viagra next day delivery
cialis professional purchase pyridium generic purchase amantadine pill
order medroxyprogesterone without prescription order periactin generic buy periactin 4mg without prescription
order provigil generic modafinil 200mg ca ivermectin 3 mg tablet dosage
accutane 40mg cheap accutane over the counter deltasone over the counter
piracetam usa sildenafil 100mg tablet sildenafil 50mg us
lasix brand buy hydroxychloroquine 200mg generic hydroxychloroquine 400mg drug
order tadalafil 5mg order anafranil 50mg pill order clomipramine
itraconazole 100 mg uk progesterone 200mg tablet order tinidazole without prescription
order norvasc buy amlodipine 5mg online cialis 40mg tablet
viagra price viagra ca lisinopril 2.5mg pills
zyvox 600mg us buy zyvox online online casinos
buy prilosec without prescription cheap essay help hard rock casino online
order lopressor 100mg purchase tenormin generic vardenafil us
purchase essays online top essay writers real casino slots online
order clomiphene 50mg generic free roulette blackjack poker online
tadalafil 20mg tablet order cialis 10mg pill buy viagra 50mg pill
cialis generic name us viagra sildenafil 100mg cheap
cheap tadalafil 40mg order tadalafil 20mg online purchase clopidogrel online
zyloprim 100mg cost allopurinol 300mg oral ezetimibe 10mg brand
order cozaar 50mg pill order topamax generic buy topiramate 100mg pills
blackjack online betting free games poker online online casino real money us
order flomax 0.4mg generic buy tamsulosin 0.4mg pill spironolactone 25mg pill
fluconazole drug purchase sildenafil sale viagra 50mg
keflex tablet erythromycin 250mg canada erythromycin oral
purchase ceftin for sale methocarbamol usa order robaxin online
best online poker sites for real money casino free spins no deposit cheap cialis 10mg
desyrel tablet sildenafil without prescription buy sildenafil 100mg sale
where can i buy an essay cheap dissertation help ivermectin 5
prednisone medication buy deltasone 5mg online oral amoxicillin 250mg
lasix tablet order doxycycline 200mg pill order hydroxychloroquine 200mg online
fildena buy online buy rhinocort generic order budesonide generic
purchase tretinoin generic avanafil pill avanafil 200mg generic
tadalafil online order buy tadalafil 10mg pill order indocin 50mg generic
lamisil ca order amoxicillin 500mg generic buy trimox without prescription
naproxen order naproxen order order prevacid 15mg without prescription
tadalafil liquid play casino casino online slots
ivermectin brand name buy stromectol 6mg without prescription order dapsone 100mg for sale
play for real online casino games gambling casino casino near me
nifedipine pills allegra medication order fexofenadine 180mg for sale
order ramipril 10mg sale amaryl price buy arcoxia 120mg sale
doxycycline online order cleocin 300mg price order cleocin 150mg without prescription
buy generic tadacip 10mg order clopidogrel 75mg online buy trimox 250mg generic
esomeprazole 20mg pill order clarithromycin 250mg generic lasix over the counter
order minocycline 100mg generic buy minocycline 100mg online cheap brand hytrin 5mg
tadalafil 5mg sale Best price cialis viagra over the counter
modafinil 200mg uk buy provigil 100mg phenergan order online
price of ivermectin prednisone oral order prednisone 5mg online cheap
purchase ondansetron online cheap trimethoprim tablet sulfamethoxazole uk
buy azathioprine for sale order generic imuran 25mg purchase naproxen without prescription
order simvastatin 20mg order simvastatin without prescription viagra sildenafil 50mg
generic uroxatral trazodone uk diltiazem 180mg without prescription
Пребывание каждого человека в постоянной опасности и осознание бессилия против природы объединили
людей в общество. А созданию
системы наказаний предшествовал запрет
на убийство одного индивида другим и наличие такой возможности убийства у общества в случае нарушения названного запрета.
Как пробудить интерес у мужчины советы психолога
buy phenergan online cheap order modafinil 100mg online cialis generic name
buy levofloxacin 500mg sale buy bupropion 150 mg bupropion 150 mg canada
buy cetirizine 5mg for sale order strattera 10mg online cheap buy sertraline 100mg for sale
order generic escitalopram 10mg buy cheap generic lexapro buy generic revia over the counter
buy atorvastatin generic oral atorvastatin 20mg order generic viagra
buy femara 2.5 mg without prescription cheap generic viagra viagra overnight shipping
is cialis generic cialis order otc ed pills that work
stromectol price uk isotretinoin for sale online buy generic accutane over the counter
buy provigil 200mg online purchase phenergan for sale prednisone 5mg canada
amoxil price cost zithromax buy generic prednisolone
prednisolone 20mg brand buy prednisolone for sale buy lasix no prescription
albuterol price order ventolin inhalator without prescription buy synthroid 75mcg generic
clomid 100mg us buy clomid generic generic hydroxychloroquine 400mg
order doxycycline 100mg for sale albuterol 4mg uk augmentin 375mg pills
buy atenolol 50mg sale letrozole 2.5 mg us buy letrozole online cheap
poip-nsk.ru
albendazole online order order generic medroxyprogesterone 5mg buy provera 10mg pill
praziquantel order online cyproheptadine 4 mg cheap periactin 4 mg pills
lisinopril 5mg pill cost prilosec 10mg order metoprolol 100mg online cheap
order pregabalin 75mg online pregabalin 75mg canada order dapoxetine 60mg pills
oral methotrexate order methotrexate 5mg generic reglan sale
orlistat canada xenical 60mg generic buy allopurinol 100mg for sale
buy generic hyzaar for sale purchase nexium pill buy topiramate 200mg without prescription
order sumycin 250mg baclofen where to buy order lioresal pill
zantac for sale online ranitidine 150mg cost celecoxib 100mg us
vipspark.ru
cost clopidogrel buy nizoral for sale order generic nizoral 200mg
flomax 0.2mg price buy tamsulosin online aldactone 100mg sale
purchase duloxetine generic order glipizide generic buy piracetam pills
buy ipratropium without prescription buy decadron without prescription order linezolid 600 mg pill
buy prometrium 200mg generic buy prometrium 100mg generic buy zyprexa 10mg online cheap
order nateglinide 120 mg sale capoten 120mg pills where can i buy candesartan
carbamazepine 200mg brand cost ciprofloxacin 500 mg oral lincocin 500 mg
buy estrace 1mg without prescription buy estrace pills for sale prazosin 1mg price
flagyl 200mg price purchase septra online order cephalexin online cheap
amoxicillin over the counter anastrozole pills order clarithromycin 250mg online cheap
order catapres 0.1 mg online meclizine 25mg ca where to buy spiriva without a prescription
buy minocin 100mg buy terazosin pills for sale cost actos
azipro where to buy order azipro brand gabapentin 800mg
buy ivermectin pills deltasone 5mg drug buy prednisone online
buy furosemide generic doxycycline 100mg tablet order albuterol online cheap
cost altace generic glimepiride 1mg arcoxia 120mg sale
buy asacol generic astelin 10 ml usa oral avapro 300mg
purchase temovate generic buy buspar generic cordarone online order
order diamox 250mg generic brand azathioprine purchase imuran pills
buy lanoxin paypal oral molnupiravir buy molnupiravir 200mg pill
naproxen 500mg drug order lansoprazole online cheap buy prevacid 30mg
baricitinib 2mg tablet metformin over the counter order atorvastatin 80mg online cheap
albuterol 100mcg ca buy phenazopyridine 200mg for sale order pyridium without prescription
buy montelukast 10mg amantadine 100mg without prescription brand dapsone 100 mg
nifedipine 30mg over the counter order fexofenadine brand fexofenadine 120mg
order dapoxetine online cheap generic priligy 60mg order orlistat 60mg without prescription
oral diltiazem 180mg allopurinol 100mg without prescription allopurinol drug
tetracycline 250mg tablet buy tetracycline cheap ozobax usa
ketorolac drug inderal tablet buy inderal 10mg generic
oral metoclopramide 10mg generic cozaar 50mg nexium 20mg us
methocarbamol 500mg usa order methocarbamol online purchase sildenafil pill
buy topamax 100mg generic buy sumatriptan 50mg online levofloxacin online buy
buy dutasteride online cheap buy avodart without prescription buy cheap mobic
aldactone canada buy generic spironolactone 100mg valtrex 500mg generic
buy proscar 5mg generic buy generic propecia sildenafil in usa
brand tadalafil diflucan order online top ed pills
azulfidine 500 mg cost order calan without prescription calan without prescription
generic lansoprazole 15mg prevacid for sale online protonix 40mg pill
buy ed pills without a prescription order tadalafil cialis 5mg without prescription
avlosulfon oral avlosulfon cheap purchase perindopril pills
allegra drug buy altace 5mg online cheap buy glimepiride 4mg sale
avapro pills buy avapro 150mg order buspar online
buy praziquantel 600mg generic order cyproheptadine 4 mg sale buy periactin 4mg sale
glipizide oral order piracetam for sale betnovate 20 gm oral
paracetamol 500mg generic buy anacin 500 mg sale buy pepcid 40mg sale
clomipramine drug order progesterone 100mg generic progesterone drug
diovan cost buy valsartan generic cost combivent 100mcg
order trileptal sale order trileptal online cheap buy ursodiol 150mg generic
dexamethasone 0,5 mg price decadron canada starlix uk
capoten 25 mg sale candesartan pills buy tegretol 400mg online
ciprofloxacin 500mg brand oral duricef 500mg order generic cefadroxil
buy lamivudine sale cheap accupril 10 mg buy accupril 10mg pill
cheap frumil 5 mg clindac a us buy cheap zovirax