首頁 >後端開發 >php教程 >php導出與讀取csv檔案的實作程式碼

php導出與讀取csv檔案的實作程式碼

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB原創
2016-07-25 08:56:13998瀏覽
  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