0

program fetching text file contents into array, and storing array variable values into example.csv file. The values are not storing column wise.

-----------------

text file content

                                      THE SAHARA CO-OP CREDIT SOCIETY LTD
                                                    MUMBAI
                                                          OVERDUE LIST OF                                                P NO :1
                                               PERSONAL LOAN AS ON  31/08/2014
----------------------------------------------------------------------------------------------------------------------------------
S.NO     A.NO             NAME                 SAN DATE   SAN.BAL  BALANCE DUE DATE  OVER DUE     INT P/OTHER TOTAL
----------------------------------------------------------------------------------------------------------------------------------
   1 Y        8 BAIGANPALLI SADIQ MEHABOOBSAB  16/06/00      8000     4740 16/12/02      4740    1804    332     6876   6   
   2 Y       22 INAMDAR ILIYASPEERA KHADARSAB  04/07/00      8000     7601 04/01/03      7601   14180   1699    23480   6   
   3 Y       41 SHAIKH MEHABOOB BASHASAB       07/07/00      7000     5342 07/01/03      5342    6301    374    12017   8   99XXXXXXXX
   4 Y       44 MOMIN ABBUSALEHA MEHABOOBSAB   07/07/00     10000     5401 07/01/03      5401    4571   1031    11003   6   90XXXXXXXX
   5 Y       46 BADAMI MEHABOOBSAB ABDULREHMA  07/07/00      9000     7600 07/01/03      7600    8737   2094    18431   6   
   6 Y       64 SHANWALE ARIF RAJESAB          11/07/00      7000     3881 11/01/03      3881    6105    752    10738       
   7 Y       69 INAMDAR GAFURPASHA GULAMHUSAI  11/07/00     10000     7942 11/01/03      7942   16999   1188    26129   6   
   8 Y       84 METI ABDULRAZAK HUSAINPASHA    15/07/00      7000     5314 15/01/03      5314   10448   1020    16782   6   99XXXXXXXX
   9 Y       91 INAMDAR LUKMANAHMED BANDEALI   02/08/00      7000     6858 02/02/03      6858   14178   1120    22156   6   
    -----------------------------------------------------------------------------------------------------------------------------
                                      THE SAHARA CO-OP CREDIT SOCIETY LTD
                                                    MUMBAI
                                                          OVERDUE LIST OF                                                P NO :2
                                               PERSONAL(SURETY)LOAN AS ON  31/08/2014
----------------------------------------------------------------------------------------------------------------------------------
S.NO     A.NO             NAME                 SAN DATE   SAN.BAL  BALANCE DUE DATE  OVER DUE     INT P/OTHER TOTAL
----------------------------------------------------------------------------------------------------------------------------------
  55 Y      366 JAMADAR MOHAMMEDSADIQ MOHAMME  27/10/00     13000    11687 27/04/03     11687   25324   1643    38654   8   98866226787
  56 Y      370 SOLAPUR ABDUL RASHEED MOHAMME  31/10/00     10000     8083 30/04/03      8083   10584   1971    20638   6   
  57 Y      371 SALAPUR ABDUL JABBAR MOHAMMED  31/10/00     12000     9747 30/04/03      9747   11641   2056    23444   6   
  58 Y      373 JUMNAL IBRAHIMSAB WAJIRAHMED   02/11/00     11000     7236 02/05/03      7236   11599   2377    21212   6   
  59 Y      384 BAGEWADI ABDULRAZAK AMEENSAB   23/11/00     10000     8494 23/05/03      8494   15292   1349    25135   8   
  60 Y      394 MANGOLI BANDENAWAZ LALSABALI   25/11/00     10000     9020 25/05/03      9020   18365    700    28085   8   
  61 Y      395 SAYYED IMAMJAFAR HASANSAB      25/11/00     10000     9121 25/05/03      9121   19761   1429    30311   8   
  62 Y      399 KALADGI KHURESHA MEHABOOBSAB   27/11/00     12000     9225 27/05/03      9225   18081   1381    28687   8   
  63 Y      404 KALADAGI NAZEER AHEMED ABDUL   29/11/00     13000     9984 29/05/03      9984   18716   3087    31787   6   97XXXXXXXX

 ----------------------------------------------------------------------------------------------------------------------------------
                              TOTAL =                    45584000 37038913           27435135 207939132128603 50357651

 admin
 06/08/2014
 17:55:14

----------------------

PHP CODE

<?php
$file = "YY.PRN";// Your Temp Uploaded file
$handle = fopen($file, "r"); // Make all conditions to avoid errors
$read = file_get_contents($file);
$output = str_replace("\t|\t", "\t", $read);
$lines = explode("\n", $output);
$i= 0;//initialize
foreach($lines as $key => $value){
   $data[$i] = explode("\t", $value);
    $i++;
}
function outputCSV($data) {
        $outputBuffer = fopen("php://output", 'w');
        foreach($data as $val) {
            fputcsv($outputBuffer, $val, ',', '"');
        }
        fclose($outputBuffer);
    }

$filename = "example";

    header("Content-type: text/csv");
    header("Content-Disposition: attachment; filename={$filename}.csv");
    header("Pragma: no-cache");
    header("Expires: 0");

    outputCSV($data);   

    ?
3
Contributors
2
Replies
14
Views
3 Years
Discussion Span
Last Post by almostbob
0

csv files do not store data in columns
each field in the row is only as wide as the data it contains
each row is therefore different in size
the program reading or writing the csv file is intelligent enough to parse the data and display it as columns

"S.NO","A.NO","NAME","SAN DATE","SAN.BAL","BALANCE","DUE DATE","OVER DUE","INT","P/OTHER","TOTAL"
"Y",8,"BAIGANPALLI SADIQ MEHABOOBSAB","16/06/00",8000,4740,"16/12/02",4740,1804,332,6876,6
"Y",2","INAMDAR ILIYASPEERA KHADARSAB","04/07/00",8000,7601,"04/01/03",7601,14180,1699,23480,6

or something similar, is correct as output
csv "comma separated values" is not meant to be easily human readable, it is a data transfer format.

[edit] the csv file will open with or import into excel, open-office, or any other spreadsheet program for further manipulation.
Most of the tabulation in the OP reports is added html in the report creation file, If there is a need for human readable the code there could be used as a base[/edit]

Edited by almostbob

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.