Importing fixed-width text files to Mysql with PHP

free-xbox

New Member
I'm trying to import fixed with text files into a Mysql table. I'm digging around for answers, but my main issue is that I can't figure out the logic of how I should do this. Maybe someone could offer some hints on process: Steps
1. \[code\]fopen\[/code\] the file \[code\]$file_handle = fopen("thefile.txt", "r"); \[/code\]2. Use \[code\]feof\[/code\] to go to the end of the file. Separate each line. (I have know idea why, but that $output line works.\[code\] while (!feof($file_handle) ) { $line_of_text = fgets($file_handle); $lines = explode('|', $line_of_text); $output = $lines[0] . $lines[1]. "<BR>";\[/code\]All of this works fine. It reads the fixed-width file, and displays it all as it should - line by line. But how do I setup the columns before I import it to Mysql? I thought maybe doing something like this might do the trick to define the right columns: \[code\]echo substr($output,0,5);echo substr($output,5,10);echo substr($output,16,5);\[/code\]But that doesn't work. Basically, can someone outline the steps I need to go through? I'm not asking for a solution, but at the moment, I don't even know what to Google for when I don't know what steps should come next. Sorry for the complete beginner question here, but any help would be very much appreciated. ThanksTerry[I'm not 100% sure how to import to Mysql either, but I wanted to get this much out of the way. IE: How do I setup the substrings to define my columns]
 
Back
Top