mfmondragon Posted January 27, 2007 Share Posted January 27, 2007 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/06XXXXX 1004568 I09890980 DELACRUZ, ROSA 01/09/06XXXXX 1004569 I09890990 DELACRUZ, MALOU 01/09/06XXXXX 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 More sharing options...
effigy Posted January 27, 2007 Share Posted January 27, 2007 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 https://forums.phpfreaks.com/topic/35928-help-in-my-fixed-width-text-file-php/#findComment-170672 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.