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
https://forums.phpfreaks.com/topic/35928-help-in-my-fixed-width-text-file-php/
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]

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.