欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

php导出与读取csv文件的实现代码

程序员文章站 2022-04-06 21:28:00
...
  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. ?>
复制代码

例2,fgetcsv读取一个csv文件

  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. ?>
复制代码

例3,fopen读取一个csv文件

  1. $file = "./demoCSV.csv";

  2. $fh = fopen($file, "rt");
  3. $userdata = fread($fh, filesize($file));
  4. fclose($fh);
  5. echo $userdata;

  6. ?>
复制代码