Editing
Byte order mark
(section)
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== How to see Byte order mark == === MySQL way === Using [https://www.w3resource.com/mysql/string-functions/mysql-hex-function.php MySQL HEX() function] "returns a string representation of a hexadecimal value of a decimal or string value specified as an argument." [http://sqlfiddle.com/#!9/5b46b0/1/0 Run sql on sqlfiddle.com] or Download the [https://drive.google.com/file/d/1TSjaK0q7f-ypxP-S_5SX18TlNvUW4yRJ/view?usp=sharing Sql file] directly. <pre> CREATE TABLE `articles` ( `id` varchar(50) NOT NULL, `notes` text NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8; INSERT INTO `articles` (`id`, `notes`) VALUES ('1234567890', 'no BOM'), ('1234567890', 'BOM'); ALTER TABLE `articles` ADD UNIQUE KEY `id` (`id`) USING BTREE; SELECT HEX(`id`), `id`, `notes` FROM `articles`; </pre> <table border="1" class="wikitable" > <tr> <th>HEX(id)</th> <th>id</th> <th>notes</th> </tr> <tr> <td>31323334353637383930</td> <td>1234567890</td> <td>UTF-8 without BOM</td> </tr> <tr> <tr> <td>EFBBBF31323334353637383930</td> <td>1234567890</td> <td>UTF-8 with BOM</td> </tr> <tr> </table> If the column {{kbd | key=`id`}} was only allowed integer in column value, you can use the following sql query to find the records contains BOM: <pre> SELECT * FROM `articles` WHERE HEX(`id`) REGEXP '[^0-9]+' </pre> === PHP way === PHP code<ref>[https://stackoverflow.com/questions/14674834/php-convert-string-to-hex-and-hex-to-string PHP convert string to hex and hex to string - Stack Overflow]</ref><ref>[https://www.w3schools.com/php/func_misc_unpack.asp PHP unpack() Function]</ref><ref>[https://stackoverflow.com/questions/10290849/how-to-remove-multiple-utf-8-bom-sequences-before-doctype php - How to remove multiple UTF-8 BOM sequences before "<!DOCTYPE>"? - Stack Overflow]</ref>: <pre> $string = "1234567890"; echo $string . " NOT contains BOM --> after str2hex: " . str2hex($string) . PHP_EOL; $string = "\xEF\xBB\xBF" . "1234567890"; echo $string . " contains BOM --> after str2hex: " . str2hex($string) . PHP_EOL; function str2hex($string) { $hexstr = unpack('H*', $string); return array_shift($hexstr); } </pre> Result: <pre> 1234567890 NOT contains BOM --> after str2hex: 31323334353637383930 1234567890 contains BOM --> after str2hex: efbbbf31323334353637383930 </pre> === Excel / Google sheet way === Using the [https://support.office.com/en-us/article/code-function-c32b692b-2ed0-4a04-bdd9-75640144b928 CODE function] to check the "numeric code for the first character in a text string". If the cell {{kbd | key=A1}} contains BOM, * {{kbd | key=<nowiki>=CODE(A1)</nowiki>}} returns {{kbd | key=63}} on Excel 2016 of {{Win}}<ref>[http://www.asciitable.com/ Ascii Table - ASCII character codes and html, octal, hex and decimal chart conversion]</ref> * {{kbd | key=<nowiki>=CODE(A1)</nowiki>}} returns {{kbd | key=95}} on Excel 2016 of {{Mac}} * {{kbd | key=<nowiki>=CODE(A1)</nowiki>}} returns {{kbd | key=65279}} or other numeric value e.g. {{kbd | key=28201}} on Google sheet === BASH command === Check if a UTF-8 encoded file contains a BOM. The first line result of {{kbd | key=hexdump}} mentioning ef bb bf indicates it contains a BOM <pre> % hexdump -n 3 -C filename 00000000 ef bb bf |...| 00000003 </pre> === File command === Using [https://en.wikipedia.org/wiki/File_(command) file (command)]: {{kbd | key=<nowiki>file filename.txt</nowiki>}} on {{Linux}}, {{Mac}}<ref>[https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man1/file.1.html file(1) Mac OS X Manual Page]</ref> & Cygwin on {{Win}}. See details on [[Text file encoding]] === Hex editor === Using Hext editor to open the text file. [https://zh.wikipedia.org/wiki/%E4%BD%8D%E5%85%83%E7%B5%84%E9%A0%86%E5%BA%8F%E8%A8%98%E8%99%9F 位元組順序記號 - 維基百科,自由的百科全書]
Summary:
Please note that all contributions to LemonWiki共筆 are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see
LemonWiki:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Navigation
Main page
Current events
Recent changes
Random page
Help
Categories
Tools
What links here
Related changes
Special pages
Page information