首页  >  文章  >  后端开发  >  php导出与读取csv文件的实现代码

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

WBOY
WBOY原创
2016-07-25 08:56:13944浏览
  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. ?>
复制代码


声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn