浠€涔堟槸鏂囦欢鐨凚OM澶达紝鍙夿OM澶存湁鍝簺鍧戯紵
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了浠€涔堟槸鏂囦欢鐨凚OM澶达紝鍙夿OM澶存湁鍝簺鍧戯紵相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/html' title='html'>html
鐗圭偣 cti bsp blank turn 璁剧疆 span nic鏉ヨ嚜锛?a href="https://www.cnblogs.com/qinmengjiao123-123/p/8325646.html" target="_blank">https://www.cnblogs.com/qinmengjiao123-123/p/8325646.html
Unicode瑙勮寖涓帹鑽愮殑鏍囪瀛楄妭椤哄簭鐨勬柟娉曟槸BOM銆侭OM涓嶆槸“Bill Of Material”鐨凚OM琛紝鑰屾槸Byte Order Mark銆?
--------------------------------------------------------------------------------------------------------------
1.浠€涔堟槸BOM锛?BOM鏄敤鏉ュ垽鏂枃鏈枃浠舵槸鍝竴绉峌nicode缂栫爜鐨勬爣璁帮紝鍏舵湰韬槸涓€涓猆nicode瀛楃锛?/span>"uFEFF"锛夛紝浣嶄簬鏂囨湰鏂囦欢澶撮儴銆? 鍦ㄤ笉鍚岀殑Unicode缂栫爜涓紝瀵瑰簲鐨刡om鐨勪簩杩涘埗瀛楄妭濡備笅锛? Bytes Encoding FE FF UTF16BE FF FE UTF16LE EF BB BF UTF8 鎵€浠ユ垜浠彲浠ユ牴鎹枃浠跺ご閮ㄧ殑鍑犱釜瀛楄妭鍜屼笂闈㈢殑琛ㄦ牸瀵瑰簲鏉ュ垽鏂鏂囦欢鏄摢绉嶇紪鐮佸舰寮忋€? 2. 濡備綍鏌ョ湅浣犳枃浠剁殑BOM瀛楃锛?BOM澶村湪璁颁簨鏈腑鏄湅涓嶅埌鐨? 浠TF8涓轰緥锛屾柊寤轰竴涓?.txt鏂囦欢锛岀劧鍚庢墦寮€鏂囦欢 杈撳叆 hello world 鐒跺悗鍙﹀瓨涓?姝ゆ椂鏇存敼鏂囦欢鐨勭紪鐮佹牸寮?鐢遍粯璁ょ殑ANSI 鍗矴B2312(鍥芥爣2312)缂栫爜鏀规垚UTF8 鐒跺悗閫氳繃涓嬮潰鐨刵ode浠g爜锛屾潵鎵撳嵃璇ユ枃鏈枃浠剁殑buffer 灏卞彲浠ョ湅鍒版垜浠墍璇寸殑BOM澶村瓧绗? let fs = require(鈥榝s鈥?span style="color: #000000;">); fs.readFile(鈥?/1.txt鈥?span style="color: #000000;">,function(err,data){ console.log(data) }) // <Buffer ef bb bf 68 65 6c 6c 6f 20 77 6f 72 6c 64> // 鍓嶄笁涓瓧鑺傚氨鏄搴旂殑鎴戜滑UTF8缂栫爜鐨勬枃鏈殑BOM澶村瓧绗?/span> 3.瀛樺湪鐨勯棶棰橈紵 铏界劧BOM瀛楃璧峰埌浜嗘爣璁版枃浠剁紪鐮佺殑浣滅敤浣嗘槸浠栧苟涓嶅睘浜庢枃浠剁殑鍐呭閮ㄥ垎锛屾墍浠ヤ細浜х敓涓€浜涢棶棰橈細 1.鍦ㄦ煇浜涗娇鐢ㄥ満鏅笅灏变細鏈夐棶棰樸€備緥濡傛垜浠妸鍑犱釜JS鏂囦欢鍚堝苟鎴愪竴涓枃浠跺悗锛屽鏋滄枃浠朵腑闂村惈鏈塀OM瀛楃锛屽氨浼氬鑷存祻瑙堝櫒JS璇硶閿欒銆? 2.php灏变笉鑳借瘑鍒玝om澶达紝PHP骞朵笉浼氬拷鐣OM锛屾墍浠ュ湪璇诲彇銆佸寘鍚垨鑰呭紩鐢ㄨ繖浜涙枃浠舵椂锛屼細鎶夿OM浣滀负璇ユ枃浠跺紑澶存鏂囩殑涓€閮ㄥ垎銆傛牴鎹祵鍏ュ紡璇█鐨勭壒鐐癸紝杩欎覆瀛楃灏嗚鐩存帴鎵ц锛堟樉绀猴級鍑烘潵銆傜敱姝ら€犳垚鍗充娇椤甸潰鐨?top padding 璁剧疆涓?锛屼篃鏃犳硶璁╂暣涓綉椤电揣璐存祻瑙堝櫒椤堕儴锛屽洜涓哄湪html涓€寮€澶存湁杩?涓瓧绗﹀憿锛? 4.濡備綍鍘绘帀UTF8缂栫爜鐨勮浜嬫湰鏂囦欢鐨凚OM澶?鏂规硶涓€锛氬湪鏂囦欢鍙﹀瓨涓虹殑鏃跺€欓€夋嫨鏃燘OM澶寸殑UTF8缂栫爜 鏂规硶浜岋細浣跨敤node涓殑鏂囦欢妯″潡鑾峰彇鏂囦欢鐨刡uffer鏁版嵁骞跺幓鎺夊墠涓変釜瀛楄妭锛屼唬鐮佸涓嬶細 function deleteUtf8BomHead(path) { let buf = fs.readFileSync(path); if (buf[0] == 0xef && buf[1] == 0xbb && buf[2] == 0xbf) { buf = buf.slice(3) } return buf } console.log(deleteUtf8BomHead(鈥?/1.txt鈥?);// <Buffer 68 65 6c 6c 6f 20 77 6f 72 6c 64> // 灏咷BK缂栫爜鐨刡uffer杞寲鎴恥tf8鐨勫瓧绗︿覆 // 鍦ㄨ繖閲屾垜浠寮曞叆涓€涓簱 iconv-lite let iconv = require(鈥榠conv-lite鈥?span style="color: #000000;">); fs.readFile(鈥?/2.txt鈥?span style="color: #000000;">,function (err, data) { console.log(data,鈥榪q鈥?span style="color: #000000;">); let str = iconv.decode(data,鈥榞bk鈥?span style="color: #000000;">); console.log(str); })
以上是关于浠€涔堟槸鏂囦欢鐨凚OM澶达紝鍙夿OM澶存湁鍝簺鍧戯紵的主要内容,如果未能解决你的问题,请参考以下文章
Python3鍩虹 getatime getctime getmtime 鏂囦欢鐨勬渶杩戣闂?+ 灞炴€т慨鏀?+ 鍐呭淇敼鏃堕棿