Why is the number of array elements 1 displayed when file () is used to read the empty text encoded as a UTF-8 ?? Bytes); $ number_of_orderscount ($ orders); echo $ number_of_orders; if ($ number_of_orders1 ){
Using file () to read the empty text encoded as a UTF-8, why does the number of array elements display 1? ? Php $ orders = file ("$ D [this article from the Internet (http://www.68idc.cn)] OCUMENT_ROOT /.. /data/order.txt "); $ number_of_orders = count ($ orders); echo" $ number_of_orders "; if ($ number_of_orders1 ){
Using file () to read the empty text encoded as a UTF-8, why does the number of array elements display 1?
$ Orders = file ("$ D [this article comes from the Internet (http://www.68idc.cn)] OCUMENT_ROOT/../data/order.txt ");
$ Number_of_orders = count ($ orders );
Echo "$ number_of_orders ";
If ($ number_of_orders <1 ){
Echo"
No orders pending.
Please try again later.
";
}
For ($ I = 0; $ I <$ number_of_orders; $ I ++ ){
Echo $ orders [$ I]."
";
}
?>
When I first came into contact with PHP and used the above Code to read the Order data in TXT text, the number of element elements in the array appeared.
1.The new order.txt file (the default encoding format is ANSI) is created without any addition or modification. Run the code to display $ number_of_orders = 0.
2.open the order.txt file and save it as a UTF-8 encoded file without any modification, but $ number_of_orders = 1
3.change the format of the newly created file to "order.txt" or "$ number_of_orders = 1 ".
4.add a row of data in the order.txt File $ number_of_orders = 1 and add 2 rows of Data $ number_of_orders = 2... (this is normal again)
Q: Why is the value of $ number_of_orders 1 when empty text is encoded as a UTF-8? How can we determine whether the text is empty or there is only one row of data?
------ Solution ----------------------
In Windows, if you use NotePad to save it as a UTF-8 encoded file, there will be a BOM header that identifies the file character set.
------ Solution ----------------------
Reference:
Quote: Reference:
In Windows, if you use NotePad to save it as a UTF-8 encoded file, there will be a BOM header that identifies the file character set.
Sure enough, what should I do here? How can I judge whether the text is empty? What else does notepad save? Is there any other way to create a BOM without a header?
If you use other text editors, you will not be able to use this BOM header. Microsoft just enjoys non-mainstream features.
------ Solution ----------------------
The BOM header is used to mark the character set of a text file. This is a standard practice.
The user can correctly interpret the text content based on the BOM header, so it is not a non-mainstream