Data from CSV like below, just one column
| BeKwX8iN3wzHDvCaxBD1 |
| 3rPB9t6EF3RGla28YbLE |
| OAYRwbrkctcVbrXaaTef |
| N8lxYdvx47FI7eYt5FUX |
| zwtRdHr3aYYnX9avcMjX |
.....
file content look: https://drive.google.com/a/hiiir.com/file/d/0B4ZVHStLEPq3bklUUHkzbDN1MkE/view?usp=sharing
The code
$row = 1;
if (($handle = fopen($serial['tmp_name'], "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$num = count($data);
echo "<p> $num fields in line $row: <br /></p>\n";
$row++;
for ($c=0; $c < $num; $c++) {
echo $data[$c] . "<br />\n";
}
}
fclose($handle);
}
the issue is that when I print $num, I got int(1), because they are all in one array()
array(1) {
[0]=>
"BeKwX8iN3wzHDvCaxBD1
3rPB9t6EF3RGla28YbLE
OAYRwbrkctcVbrXaaTef
N8lxYdvx47FI7eYt5FUX
zwtRdHr3aYYnX9avcMjX"}
I know fgetcsv() controll by $delimiter, and this case is ,,but it not suitable for my case. Is it possible to separate by 20 Characters?
fgetcsvif each line of the file looks like|abc|then doarray_map(function($a){ return trim($a,'|');},file($serial['tmp_name']));to get the data in a array (one entry for reach line) or usefgets()instead offgetcsv().$delimiterto everthing you need, read more: php.net/manual/en/function.fgetcsv.php