php保存文件用utf-8格式,大家都知道,PHP可以直接创建文件
例如:
- fopen('dir.txt','w');//创建并打开dir.txt
这个表示创建并打开dir.txt文件,然后就可以往里面写入数据了。问题来了,写入数据保存的格式都是ANSI,无法保存UTF8格式,如何测试都不能成功,经过上网查询,和自己实践,研究结果如下:
以下代码可以直接创建urt8格式的文本文件:
- <?php
- $f=fopen("test.txt", "wb");
- $text=utf8_encode("a!");
- //先用函数utf8_encode将所需写入的数据变成UTF编码格式。
- $text="\xEF\xBB\xBF".$text;
- //"\xEF\xBB\xBF",这串字符不可缺少,生成的文件将成为UTF-8格式,否则依然是ANSI格式。
- fputs($f, $text);
- //写入。
- fclose($f);
- ?>
这样创建出的文件编码格式确实是utf-8,但是放在文件中如果有汉字,就会出现乱码的现象,经过一番调试,代码如下:
- <?php
- $ctxtsubmit="好呀";
- $f=fopen("../".$file, "wb");
- //$text=utf8_encode($ctxtsubmit);
- //先用函数utf8_encode将所需写入的数据变成UTF编码格式。
- $text="\xEF\xBB\xBF".$ctxtsubmit;
- //"\xEF\xBB\xBF",这串字符不可缺少,生成的文件将成为UTF-8格式,否则依然是ANSI格式,www.wfuyu.com 程序员人生网。
- fputs($f, $text);
- //写入。
- fclose($f);
- ?>
波比源码 – 精品源码模版分享 | www.bobi11.com
1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长!
2. 分享目的仅供大家学习和交流,您必须在下载后24小时内删除!
3. 不得使用于非法商业用途,不得违反国家法律。否则后果自负!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系管理员处理!
6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需!
7. 本站源码并不保证全部能正常使用,仅供有技术基础的人学习研究,请谨慎下载
8. 如遇到加密压缩包,请使用WINRAR解压,如遇到无法解压的请联系管理员!
波比源码 » php保存文件用utf-8格式
波比源码 » php保存文件用utf-8格式
levofloxacin 500mg ca buy levaquin 500mg pills
order indomethacin 50mg pills lamisil 250mg usa order amoxicillin 250mg pill
generic prednisone 5mg buy generic viagra 100mg sildenafil generic
buy doxycycline generic doxycycline without prescription furosemide 40mg tablet
buspar 10mg ca buspirone 5mg canada buy ditropan online cheap
order isosorbide 20mg without prescription telmisartan over the counter telmisartan 20mg pills
canadian cialis online pharmacy cialis dosage 40 mg viagra price
naltrexone cost order naltrexone generic abilify uk
buy accutane 40mg online cheap buy deltasone online buy prednisone pill
buy generic aralen buy olumiant 4mg online cheap baricitinib for sale
order amlodipine 10mg sildenafil uk order tadalafil 20mg sale
cost prilosec 20mg paper assistance play slots for real money united states
vardenafil uk vardenafil 10mg for sale medrol 8mg oral
write my essay help paperwriter viagra 100mg canada
clomiphene 50mg cheap albuterol online buy best casinos
buy tadalafil online cheap buy clopidogrel 150mg sale plavix 75mg over the counter
methotrexate buy online reglan 10mg pill generic reglan 20mg
sildenafil next day delivery buy viagra 50mg online cialis oral
buy desyrel online cheap aurogra 50mg over the counter buy sildenafil 50mg online cheap
pay for research papers cheap term papers stromectol for sale
buy prednisone generic prednisone for sale order amoxicillin for sale
viagra 100mg without prescription sildenafil 50mg tablet cialis pharmacy
order azithromycin 500mg for sale cheap prednisolone 40mg neurontin over the counter
online roulette real money order generic provigil provigil tablet
purchase tadalafil without prescription order tadacip for sale indomethacin over the counter
order generic albuterol 100 mcg buy protonix 20mg generic cipro over the counter
cheap cialis 20mg Cialis online play online blackjack
buy amoxil 250mg generic order amoxicillin 500mg without prescription buy stromectol europe
dapoxetine over the counter order avanafil 100mg without prescription buy motilium 10mg sale
buy nortriptyline sale buy paxil 10mg without prescription paroxetine for sale
indomethacin 75mg pill generic indomethacin cenforce price
pepcid 40mg ca order tacrolimus buy remeron
cost tadalafil tadacip pills amoxicillin 250mg generic
nexium generic lasix canada lasix 100mg price
order tadalafil 10mg sale top ed drugs otc ed pills
glucophage over the counter order nolvadex for sale cost tamoxifen 10mg
clomid 100mg generic order clomid 100mg sale prednisolone 10mg cheap
sildenafil cost male ed pills oral finasteride
zofran over the counter zofran 8mg uk bactrim pills
ventolin inhalator without prescription generic synthroid augmentin online order
isotretinoin 20mg cheap buy absorica online cheap zithromax 500mg for sale
order generic vibra-tabs buy vardenafil 10mg zovirax 400mg usa