-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcsv_fix.php
More file actions
31 lines (29 loc) · 747 Bytes
/
csv_fix.php
File metadata and controls
31 lines (29 loc) · 747 Bytes
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
<?php
function something($number)
{
$locale = localeconv();
return number_format($number,
2,
$locale['decimal_point'],
'');
}
function fixit($file) {
$in = fopen($file, 'r');
$out = fopen($file.'-out.csv', 'w');
$locale = localeconv();
while ($data = fgetcsv($in)) {
foreach ($data as $key => $value) {
if (preg_match('#^\d\.\d+E\d$#', $value)) {
$data[$key] = something((float)$value);
} else if (preg_match('#^\d{4,}\.\d\d$#', $value)) {
$data[$key] = str_replace('.', $locale['decimal_point'], $value);
}
}
fputcsv($out, $data);
}
fclose($in);
fclose($out);
}
setlocale(LC_ALL, 'id');
fixit('/home/captain_kuro/Downloads/KHANDARW0705_1168886619.CSV');
// print_r(localeconv());