SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member
    Join Date
    Jan 2007
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    help in my fixed-width text file & php

    hi guys, id like to ask how can i do this:

    1. the text file should be uploaded by the user (is there any codes you can provide)

    2. i have a text files that is not comma-delimited, only fixed width. though basically i just need 2 - 3 fields to be imported to the database. (the reason why i need this because of the nature of legacy database we're using... btrieve, that's why i just rely to text files being generated)

    here's the sample data:

    XXXXX 1004567 I09890990 DELACRUZ, JUAN 01/09/06
    XXXXX145 1004568 C09890990 DELACRUZ, JUAN 01/09/06
    XXXXX890 1004569 I09890990 DELACRUZ, JUAN 01/09/06
    XXXXX 1004575 C09890990 SANTOS, MARY GRACE 01/09/06

    assuming that i need the records for the second & third column? how can i get those?

    i hope you could help me... thanks!

  2. #2
    SitePoint Member
    Join Date
    Jan 2007
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: help in my fixed-width text file & php

    i got it all working now!!! huh!

    but my problem is, why is it when there's always a blank data being displayed?

    <?php

    $fp = @fopen("studlst.txt", "r") or die("Couldn't open file");
    $data = @fread($fp, filesize($fp));

    while(!feof($fp))
    {
    $data .= @fgets($fp);
    }

    fclose($fp);
    $values = explode("\n", $data);
    foreach ($values as $val)
    {
    $read = sscanf($val,"%24s %s %d %s %s %s");
    echo $read[2]." - ".$read[5];
    echo ("<br />");
    }

    ?>

    here's the result code...

    RE - Cust
    ============
    127119 - I021258
    127121 - I017812
    127195 - I021275
    127327 - I010898
    127522 - I019835
    127630 - I004060
    127638 - I021344
    127641 - I016019
    127644 - I018246
    127697 - I019553
    127701 - I020584
    127718 - I019415
    127724 - I021357
    127725 - I019912
    127727 - I018056
    127730 - I016662
    127736 - I021359
    127741 - I013305
    127749 - I018504
    127751 - I020617
    127753 - I005730
    127765 - I003125
    127767 - I021361
    127768 - I021362
    127773 - I014573
    127780 - I017331
    127785 - I017953
    127794 - I018925
    -

    NOTE: try to look on the " - " being generated as well... it should not be like this because if i will insert this to my database it will produce an error, right? because my field is set to "NOT NULL"

    pls. help me... thanks!

  3. #3
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Well I guess your last line of date ends with a CR (\n) so your explode statement tries to read the next line, which is blank, it outputs this blank data, with the - symbol inbetween.
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  4. #4
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Well I guess your last line of date ends with a CR (\n) so your explode statement tries to read the next line, which is blank, it outputs this blank data, with the - symbol inbetween.
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  5. #5
    SitePoint Member
    Join Date
    Jan 2007
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    so what can i do with this one sir?

  6. #6
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You could check that $read actually has something in it before outputting !
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  7. #7
    SitePoint Member
    Join Date
    Jan 2007
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i solved it already. thanks anyways!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •