Open CSV file with PHP

WBOY
Release: 2016-07-25 09:02:12
Original
1009 people have browsed it
Open CSV file with PHP
  1. //Set UTF-8 encoding
  2. setlocale(LC_ALL, 'en_US.UTF-8');
  3. //csv path
  4. $csv_file = "csv/excel.csv";
  5. //Open in read-only mode File
  6. $handle = fopen($csv_file, "r");
  7. //Define the result array
  8. $listarr = array();
  9. //Open a row in csv and split it into an array with ","
  10. while($data = fgetcsv($handle, 1000, ",")){
  11. $num = count($data);
  12. for($i=0; $i<$num; $i++){
  13. $data[$i] = mb_convert_encoding ($data[$i],"UTF-8","UTF-8");
  14. }
  15. $listarr[] = $data;
  16. }
  17. return $listarr;
Copy code


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!