note 120296 deleted from function.fputcsv by peehaa
| From: | peehaa@php.net | Date: | Fri, 09 Dec 2016 22:35:56 +0000 |
| Subject: | note 120296 deleted from function.fputcsv by peehaa | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-208368@lists.php.net to get a copy of this message | ||
Note Submitter: toni
----
I have a small code,how to read and insert Informations in a CSV File with "fputcsv" and
"fgetcsv":
<?php
//Insert Informations
$listwithinput=array(
array("First","Second","Third"),
array("A","B","C"),
array("1","2","3")
);
$pointer=fopen("list.csv","a+");
if($pointer!=false)
{
foreach($listwithinput as $value)
{
fputcsv($pointer,$value,";");
}
fclose($pointer);
}
else
{
echo"<p> It was not possible to open the File!</p>";
}
//Read Informations
$pointer=fopen("list.csv","a+");
if($pointer!=false)
{
while($row=fgetcsv($pointer,500,";"))
{
echo"<p>
Row1: ".$row[0]."<br>
Row2: ".$row[1]."<br
Row3: ".$row[2]."<br></p>";
}
fclose($pointer);
}
else
{
echo"<p> It was not possible to open the File!</p>";
}
?>