How to use Filesystem fputcsv in PHP
In this article I am going to explain about fputcsv function in PHP.
PHP fputcsv() Function
The filesystem fputcsv function is used to format line as CSV and write to file pointer.
Syntax of fputcsv function
fputcsv(file, fields, seperator, enclosure) |
Parameters in fputcsv function
It have four parameter:
Parameter |
Description |
file |
It specifies the open file to write. |
fields |
It specifies which array to get data. |
seperator |
A character that specifies the field separator. |
nclosure |
A character that specifies the field enclosure character. |
Example of filesystem fputcsv function
<html>
<body>
<?php
$list = array (
array('Mind', 'cracker', 'Network'),
array('123', '456', '789'),
);
$fp = fopen('C:\wamp\www\Dinesh\Mcn.txt', 'w');
foreach ($list as $fields) {
fputcsv($fp, $fields);
}
$fp1 = fopen('C:\wamp\www\Dinesh\Mcn.txt', 'r');
while(! feof($fp1))
{
echo fgets($fp1). "<br />";
}
fclose($fp);
?>
</body>
</html>
|
Output:
You may also want to read these related articles :here
Ask Your Question
Got a programming related question? You may want to post your question here
Programming Answers here