Use file () to read the empty text encoded for the UTF-8, why is the number of array elements 1

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.