這篇文章主要介紹“如何解決php中隱形字符65279問(wèn)題”,在日常操作中,相信很多人在如何解決php中隱形字符65279問(wèn)題問(wèn)題上存在疑惑,小編查閱了各式資料,整理出簡(jiǎn)單好用的操作方法,希望對(duì)大家解答”如何解決php中隱形字符65279問(wèn)題”的疑惑有所幫助!接下來(lái),請(qǐng)跟著小編一起來(lái)學(xué)習(xí)吧!
php隱形字符65279解釋如下:
UTF-8 編碼的文件可以分為無(wú) BOM 和 BOM 兩種格式。
何謂BOM?
"EF BB BF" 這三個(gè)字節(jié)就叫BOM,全稱(chēng)是"Byte Order Mard"。在utf8文件中常用BOM來(lái)表明這個(gè)文件是UTF-8文件,而B(niǎo)OM的本意是在utf16中用。
utf-8文件在php中輸出的時(shí)候bom是會(huì)被輸出的,所以要在php中使用utf-8,必須要是使用不帶bom頭的utf-8文件。
常用的文本編輯軟件對(duì)utf-8文件保存的支持方式并不一樣,使用的時(shí)候要特別留意。
例如:
1、使用ultraedit時(shí),另存時(shí)會(huì)有“UTF-8”和“UTF-8 - 無(wú)BOM”兩種選擇。
2、 window的記事本保存的是帶bom的。
3、EditPlus軟件不同版本對(duì)utf-8的保存支持不一樣,例如:2.31版本保存的是不帶bom的,2.11版本保存的是帶bom的。
把utf-8文件頭去掉的辦法:
1、使用ultraedit另存,選擇“UTF-8 - 無(wú)BOM”
2、一個(gè)很有用的php程序,放在站點(diǎn)根目錄下運(yùn)行,會(huì)把目錄下全部utf-8文件的bom頭去掉,代碼如下:
//remove the utf-8 boms //by magicbug at gmail dot com if (isset($_GET['dir'])){ //config the basedir $basedir=$_GET['dir']; }else{ $basedir = '.'; } $auto = 1; checkdir($basedir); function checkdir($basedir){ if ($dh = opendir($basedir)) { while (($file = readdir($dh)) !== false) { if ($file != '.' && $file != '..'){ if (!is_dir($basedir."/".$file)) { echo "filename $basedir/$file ".checkBOM("$basedir/$file")." <br>"; }else{ $dirname = $basedir."/".$file; checkdir($dirname); } } } closedir($dh); } } function checkBOM ($filename) { global $auto; $contents = file_get_contents($filename); $charset[1] = substr($contents, 0, 1); $charset[2] = substr($contents, 1, 1); $charset[3] = substr($contents, 2, 1); if (ord($charset[1]) == 239 && ord($charset[2]) == 187 && ord($charset[3]) == 191) { if ($auto == 1) { $rest = substr($contents, 3); rewrite ($filename, $rest); return ("<font color=red>BOM found, automatically removed.</font>"); } else { return ("<font color=red>BOM found.</font>"); } } else return ("BOM Not Found."); } function rewrite ($filename, $data) { $filenum = fopen($filename, "w"); flock($filenum, LOCK_EX); fwrite($filenum, $data); fclose($filenum); }
到此,關(guān)于“如何解決php中隱形字符65279問(wèn)題”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)?lái)更多實(shí)用的文章!
分享文章:如何解決php中隱形字符65279問(wèn)題-創(chuàng)新互聯(lián)
網(wǎng)站URL:http://jinyejixie.com/article36/dcpdpg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供動(dòng)態(tài)網(wǎng)站、移動(dòng)網(wǎng)站建設(shè)、品牌網(wǎng)站制作、網(wǎng)站收錄、微信公眾號(hào)、App設(shè)計(jì)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容