php导出与读取csv文件的实现代码
时间:2021-07-01 10:21:17
帮助过:25人阅读
- $users = file("./demoCSV.csv");
- foreach ($users as $user) {
- list($name, $email, $phone) = explode(",", $user);
- echo "
$name ($email) Tel. $phone "; - } //edit by bbs.it-home.org
- ?>
例2,fgetcsv读取一个csv文件
$fh = fopen("./demoCSV.csv", "r"); - while (list($name, $email, $phone) = fgetcsv($fh, 1024, ",")) {
- echo "
$name ($email) Tel. $phone "; - } //edit by bbs.it-home.org
- ?>
例3,fopen读取一个csv文件
$file = "./demoCSV.csv"; - $fh = fopen($file, "rt");
- $userdata = fread($fh, filesize($file));
- fclose($fh);
echo $userdata; - ?>
|