How do I read from the second line when I read a CSV file? and garbled problems.

Source: Internet
Author: User
To read a CSV file in this way:

 
  

All the data is taken out at once, the first line of the file is the title, the second row is to take the data, how to take?

Also read the non-English characters displayed as garbled, how to deal with it?

Reply content:

To read a CSV file in this way:

 
  

All the data is taken out at once, the first line of the file is the title, the second row is to take the data, how to take?

Also read the non-English characters displayed as garbled, how to deal with it?

1. The while before adding a row fgets ($file);
2. Your file encoding is what, the display should be what code, figure out later with iconv/mbstring transcoding a bit better.

1. At the top of the page, add: Header ("Content-type:text/html;charset=utf-8");
2.

 
  

Another way:

$str = file_get_contents ("Contacts.csv");  $arr = explode ("\ n", $str);p rint_r ($arr [1]);

$file = fopen ("Contacts.csv", "R"), Fgetcsv ($file), while (!feof ($file) && $data = Fgetcsv ($file)) {        $csv _ Datas = Array (), $csv _datas[' column1 ') = Mb_convert_encoding ($data [1], ' UTF-8 ', ' Utf-8,shift_jis '); // ...}

It is worth noting that the first column to add the extra columns, the real data from the second column only to read the right, I do not know why.

  • 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.