I was trying to find answer but i was not successful, please help.
I'm trying to populate multiple rows from data.txt by preg_match to single row or column in data.csv. It needs to be in single array because I need only unique numbers. -> or any other option the get only unique numbers
I was not able to merge arrays to single array and populate it like one array to single row. I will be truly happy for any advice.
Here is my simplified code:
$filename = 'data.txt';
$fupids = array ();
$handle = fopen($filename, "r");
if (!$handle) exit;
while (($line = fgets($handle)) !== false) {
if (preg_match_all('/([0-9]{8})/',$line,$output)) {
$fupid = $output[0];
$file = fopen('data.csv', 'a+');
fputcsv($file, array_unique($output[0]));
}
}
fclose($file);
Here is my simplified data.txt :
10153231,10159512,10159512,10159512
10141703,10160541,10160541
10165815,10158007,10158007
current csv output :
10153231,10159512
10141703,10160541
10165815,10158007
desirable output is only one row or maybe better one column like this:
10153231,10159512,10141703,10160541,10165815,10158007
Thanks all for help.