Jump to content

help in my fixed-width text file & php


mfmondragon

Recommended Posts

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
XXXXX            1004568            I09890980                DELACRUZ, ROSA      01/09/06
XXXXX            1004569            I09890990                DELACRUZ, MALOU    01/09/06
XXXXX            1004575            I09890990                DELACRUZ, MARIAN  01/09/06
Link to comment
Share on other sites

Based on the format you've given, this will work:

[code]
<pre>
<?php
// This would really be your file.
$data = array(
'XXXXX            1004567            I09890990                DELACRUZ, JUAN      01/09/06',
'XXXXX            1004568            I09890980                DELACRUZ, ROSA      01/09/06',
'XXXXX            1004569            I09890990                DELACRUZ, MALOU    01/09/06',
'XXXXX            1004575            I09890990                DELACRUZ, MARIAN  01/09/06'
);
// This would really be a loop through your file.
foreach ($data as $line) {
$pieces = preg_split('/\s{2,}/', $line);
print_r($pieces);
}
?>
</pre>
[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.