Unicode 的BOM (byte order mark) @ 工作小錦囊 - 隨意窩

文章推薦指數: 80 %
投票人數:10人

Unicode 的BOM (byte order mark) ... A Byte Order Mark (BOM) is the character at code point U+FEFF ... FF FE 00 00, UTF-32, little-endian. ­工作小錦囊AByteOrderMark(BOM)isthecharacteratcodepointU+FEFF("zero-widthno-breakspace"),whenthatcharacterisusedtodenotetheendiannessofastringofUCS/UnicodecharactersencodedinUTF-16orUTF-32and/orasamarkertoindicatethattextisencodedinUTF-8,UTF-16orUTF-32.http://en.wikipedia.org/wiki/Byte_Order_Mark這個問題發現在某個script輸出兩個staticutf-8encodedfile,導致html的layout在IE會亂掉的情況.readfile("template1");...htmlcodereadfile("template2");其中template1跟template2都是ucs-bom(leadingbyte是efbbbf)BytesEncodingForm0000FEFFUTF-32,big-endianFFFE0000UTF-32,little-endianFEFFUTF-16,big-endianFFFEUTF-16,little-endianEFBBBFUTF-8為了輸出的效能,readfile不能以file_get_contents取代,有幾種寫法1.加上htmlremark:echo"realcontents.....2.從outputbuffer中間把這些東西strip掉functionstrip_u8_bom($str){returnstr_replace("\xEF\xBB\xBF","",$str);}functionStripUtf8Bom($data){if(substr($data,0,3)=="\xEF\xBB\xBF")returnsubstr_replace($data,'',0,3);return$data;}3.把template的BOM去掉if($_SERVER["argc"]<2){printf("Usage:%sfile[file...]\n",$_SERVER['argv'][0]);exit;}$argc=$_SERVER["argc"];for($i=1;$i



請為這篇文章評分?