How to tell if a file is a. csv file from the contents of a file

Source: Internet
Author: User
How to tell if a file is a. csv file from the contents of a file
The expansion name is not allowed in this area. Afraid of others to change the name of expansion
And I installed inside whether to include a comma, because some files are read out of the content is garbled? The result is that it will read garbled characters into commas?
And I need to judge the rigorous methods and theories of the. csv file, not for granted. In fact, only by the comma is not rigorous ah, in fact, garbled may become a comma, its 21 files have a comma is a qualified CSV file

Thank you, Master.

------Solution--------------------
No way
------Solution--------------------
Try Str_getcsv Analysis
http://php.net/manual/en/function.str-getcsv.php
Use error to determine
------Solution--------------------
No cases are garbled by reading commas

The CSV file is a text file, and the only thing that can be recognized is that each row has an equal number of column separators (the default is a comma)
Consider a qualified CSV file when the number of column separators that detect more than 80% rows is equal, given that there may be commas in the content (the content needs to be enclosed in quotation marks)

In addition, non-standard CSV, which is the content of the character type, is not enclosed in double quotation marks. At least php5.3 for win is not available
The Fgetcsv or Str_getcsv function reads correctly
------Solution--------------------
The CSV file expresses an array
If each row has a different number of columns, it is not a CSV
------Solution--------------------
Full Name

Comma separated Values
Edit this paragraph
Rules

1 The opening is not left empty to the behavior unit.
2 can contain or do not contain column name, including column name in the first line of the file.
31 rows of data do not collapse, no blank line.
4 A comma (that is,) is used as a delimiter, the column is empty also to express its existence.
5 column Contents If there are half-width commas (that is,) enclose the field value with a half-width quotation mark (that is, "").
6 column Contents If there is a half-width quotation mark (that is, "), you should replace it with a half-width double quotation mark (" ") and enclose the field value with a half-width quotation mark (" ").
7 file read-write quotation marks, comma operation rules are mutually inverse.
8 Internal code format is not limited, can be ASCII, Unicode or other.
9 special characters are not supported
------Solution--------------------
According to the requirements of the rules
------Solution--------------------
What format do you want the user's CSV to be? In addition, for the file, there is no garbled concept, only the concept of byte,
Garbled only a few bytes can not be displayed in the specified character set (such as GB2312).
------Solution--------------------
Use a comma (that is,) as a delimiter, and the column is empty to express its existence
This is important.
------Solution--------------------
Find a CSV to lead to other formats class can be successful is not, it is not, this curve to the salvation of the bar
------Solution--------------------
Explore

Reference:
Use a comma (that is,) as a delimiter, and the column is empty to express its existence
This is important.

I told you, did you say that?
If you have a word inside of a comma, you read the content, do you know whether the comma is a delimiter or a valid character?


You can follow a comma to read a. csv file

But you only have to use commas to make a difference. CSV file this is too farfetched. The reason is too inadequate

This comma is not a sufficient condition
  • 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.