csv - Using tabs spacing in php for text file -
i'm reading csv file , printing data csv file 2 .txt
files. output of text files follows
john georgina,sinclair,408999703657,cheque,"first national bank",fourways,275.00,12/01/2012 toby,henderson,401255489873,cheque,"first national bank",edenvale,181.03,12/13/2012
here code:
$file_handle = fopen("debitorders.csv", "r") or die("can't open debitorders.csv"); $absafile = fopen("absa.txt", "w") or die("can't open absa.txt"); $firstnationalbankfile = fopen("first national bank.txt", "w") or die("can't open first national bank.txt"); while (!feof($file_handle) ) { $debitorders = fgetcsv($file_handle, 1024, ","); if ($debitorders[4] == "absa"){ print_r ($debitorders[4] . "<br />"); fputcsv($absafile, $debitorders); $absa_bank = "absa"; fopen("absa.txt", "a"); file_put_contents('absa.txt', $absa_bank, file_append); } if ($debitorders[4] == "first national bank"){ $fnb_bank = "first national bank"; print_r ($debitorders[4] . "<br />"); fputcsv($firstnationalbankfile, $debitorders); $fnb_bank = "first national bank"; fopen("first national bank.txt", "a"); file_put_contents('first national bank.txt', $fnb_bank, file_append); } } fclose($file_handle); fclose($absafile); fclose($firstnationalbankfile);
how can put tab spaces in output file instead of commas, output instead looks this:
john georginasinclair 408999703657 cheque first national bank fourways 275.0012/01/2012 tobyhenderson 401255489873 cheque first national bank edenvale 181.0312/13/2012
any appreciated. thank you
i did similar while although other way around. replaced tabs commas. here code used:
preg_replace('/[ ]{2,}|[\t]/', ',', $string);
the code above removed 2 tabs , replaced 1 comma. maybe try way:
preg_replace(',', '/[ ]{1,}|[\t]/', $string);
Comments
Post a Comment