-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcsv.php
36 lines (33 loc) · 919 Bytes
/
csv.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
function arrayToCSV($inputArray)
{
$csvFieldRow = array();
foreach ($inputArray as $CSBRow) {
$csvFieldRow[] = str_putcsv($CSBRow);
}
$csvData = implode("\n", $csvFieldRow);
return $csvData;
}
function str_putcsv($input, $delimiter = ',', $enclosure = '"')
{
// Open a memory "file" for read/write
$fp = fopen('php://temp', 'r+');
// Write the array to the target file using fputcsv()
fputcsv($fp, $input, $delimiter, $enclosure);
// Rewind the file
rewind($fp);
// File Read
$data = fread($fp, 1048576);
fclose($fp);
// Ad line break and return the data
return rtrim($data, "\n");
}
$inputArray = array(
array("First Name", "Last Name", "Identification Number"),
array("Kim","Thomas","8001"),
array("Jeffery","Robert","8021"),
array("Helan","Albert","8705")
);
print "<PRE>";
print $CSVData = arrayToCSV($inputArray);
?>