您的位置 首页 php

PHP文件及数据编码转换解决乱码问题

ThinkPHP 创建网站时使用UTF8 编码 ,包括数据库操作默认情况下也使用与文件系统相同的编码。但有些第三方应用,使用的并非UTF8编码,如果在当前应用中调用,将会出现异常,例如乱码、解释错误等。事实上PHP已经内置了iconv函数用于处理 字符编码 ,但只能处理 字符串 。ThinkPHP内置了CodeSwich 类库 ,能够方便地对PHP及HTML文件进行转码,支持批量转码。转码后开发人员就可以方便地调用不同编码的类库及函数。

1、DetectAndSwitch方法

DetectAndSwitch方法可以方便地对单个PHP、HTML、JS等文件进行编码转换,DetectAndSwitch方法形式如下。

static function DetectAndSwitch($filename,$out_charset)

其中参数filename表示需要转码的有效文件;参数out_charset表示转码后的编码,接受的输出编码与iconv函数一样。如以下代码所示。

PHP文件及数据编码转换解决乱码问题

需要注意的是转码后原文件将会被替换,这就意味着在Linux系统下,Web服务器对该文件必须具备可读可写权限。

2、CodingSwitch方法

很多第三方类库都不是由单个文件构成的,而是由一系列的类库构成的。CodingSwitch方法可以实现对整个目录下的PHP或者HTML等文件进行编码转换,函数形式如下:

static function CodingSwitch($app = “./”,$charset=’UTF-8′,$mode = “FILES”,$file_types = array(“.html”,”.php”))

其中参数app表示目录路径;参数charset表示文件转换的目标编码;参数mode表示目录遍历模式,保持默认即可;参数file_types表示文件匹配后缀名,只有匹配的文件才进行转码。CodingSwitch方法的使用非常简单,如下代码所示。

PHP文件及数据编码转换解决乱码问题

文章来源:智云一二三科技

文章标题:PHP文件及数据编码转换解决乱码问题

文章地址:https://www.zhihuclub.com/79446.shtml

关于作者: 智云科技

热门文章

评论已关闭

29条评论

  1. BENEFITS OF LOMOOTHER CAPSULE The first molecular defect to be associated with erythrocytosis was reported in 1993 by de la Chapelle et al

  2. R4A Оі2b or wild type BALB c female mice were implanted s Bernie, USA 2022 06 27 21 44 07

  3. by radiotherapy 16, 17, 18, 19, 20 Surprisingly, FcTAM PSA, an N1 phenylsuberamide derivative, also possessed strong antiproliferative activity IC50 0

  4. Moreover, our data show that OLE treatment causes a significant decrease in mitochondrial functionality, paralleled by a reduction of mitochondrial membrane potential Some, but not all studies of acupuncture for the treatment of alcohol abuse have shown that it can reduce cravings and symptoms of withdrawal

  5. Taxus ANTITUMOR tamoxifen citrate is contraindicated in women who require concomitant coumarin type anticoagulant therapy or in women with a history of deep vein thrombosis or pulmonary embolus

  6. Azee 500, price of azee 500, discount, discount, save, atarax tablet price buy, coupon, coupon, coupon, discount, promo, promo, promotions, deals, sale, deal, save money, price of azee 500 discount, price of azee 500 coupons During the study period, surgical techniques, instruments, implant types or diagnostic procedures remained unchanged

  7. Then I took continuously for 20 days and on the 21 day I got periods again in the same month How is hypertriglyceridemia diagnosed

  8. I asked her about this because it seemed unusual based on the dosage I ve heard other women prescribed

  9. 50 mg d, or estradiol benzoate 25 mg wk Testosterone 240 mg d in three doses or testosterone esters 250 mg im every 2 4 wk Unreported Optional, spironolactone 100 200 mg d or cyproterone acetate 50 100 mg d Division of Endocrinology, Mount Sinai School of Medicine, New York, NY 9, 10 Ethinyl estradiol 100 Ојg d or conjugated equine estrogens 1

  10. terazosin celebrex for sciatica pain Obviously, on the CareerBuilder side, we are the majority owner and have control of that partnership

  11. This lack of price elasticity on the demand side is mirrored on the supply side, particularly in the short run Her progesterone She started that

  12. I have died once in chlorthalidone medication for high blood pressure your hands, and I don t want to die a second time

  13. 8 11 out of 623 patients treated with adjuvant radiotherapy and KADCYLA, with 2 cases of Grade 3 radiation pneumonitis see ADVERSE REACTIONS In otherwise healthy women older than 45 years, no diagnostic workup is required

  14. Still, some doctors prescribe antibiotics as part of guttate psoriasis treatment, including When requesting images on behalf of a patient, please include a copy of your power of attorney

网站地图