I have written code to take .csv files into a database. The problem I have now is that the data has to be converted to a to a tab delimited format.
I am using PHP Version 4.3.4
here is the code I am using to write the file
$count="0";
$sql=("SELECT * FROM modpay");
$results = mysql_query($sql);
$tm=date("h.i.s.A");
$d=date("m-j-Y");
if(!$file_handle = fopen('converted/modpay/modpay_'.$d.'_'.$tm.'.txt', 'a')){echo "Cannot open file";}
while($row=mysql_fetch_array($results)){
$client_code = $row['client_code'];
$debtor_acct_num = $row['debtor_acct_num'];
$company_name = $row['company_name'];
$first_name = $row['first_name'];
$last_name = $row['last_name'];
$address = $row['address'];
$city = $row['city'];
$state = $row['state'];
$zip_code = $row['zip_code'];
$phone = $row['phone'];
$amount = $row['amount'];
$routing_aba = $row['routing_aba'];
$bank_acct_num = $row['bank_acct_num'];
$account_type = $row['account_type'];
$signature = $row['signature'];
$cc_num = $row['cc_num'];
$exp_month = $row['exp_month'];
$exp_year = $row['exp_year'];
$cardholder = $row['cardholder'];
$comment = $row['comment'];
$data="$client_code,$debtor_acct_num,$company_name,$first_name,$last_name,$address,$city,$state,$zip_code,$phone,$amount,$routing_aba,$bank_acct_num,$account_type,$signature,$cc_num,$exp_month,$exp_year,$cardholder,$comment";
$count++;
if(!fwrite($file_handle, $data."\n")){echo "Cannot write to file";}
}
fclose($file_handle);
I tried to change the $data to be separated by \t hoping that it would add the tab space into the file but didnt work... it just printed
field info\t field info2\t
If anyone can help I would appreciate it.
Thanks