Implementation code for php exporting and reading csv files

WBOY
Release: 2016-07-25 08:56:13
Original
932 people have browsed it
  1. $users = file("./demoCSV.csv");
  2. foreach ($users as $user) {
  3. list($name, $email, $phone) = explode(" ,", $user);
  4. echo "

    $name ($email) Tel. $phone

    ";
  5. } //edit by bbs.it-home.org
  6. ?>
  7. < !--
  8. A,a@example.com,11111
  9. B,b@example.com,22222
  10. -->
Copy code

Example 2, fgetcsv reads a csv file

  1. $fh = fopen("./demoCSV.csv", "r");
  2. while (list($name, $email, $phone) = fgetcsv ($fh, 1024, ",")) {
  3. echo "

    $name ($email) Tel. $phone

    ";
  4. } //edit by bbs.it-home.org
  5. ? >

Copy code

Example 3, fopen reads a csv file

  1. $file = "./demoCSV.csv";
  2. $fh = fopen($file, "rt");
  3. $userdata = fread($fh, filesize($file));
  4. fclose($fh);

  5. echo $userdata;

  6. ?>

Copy code


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!