开发者

How would I go about by creating a parser which has the ability to import txt into mysql

开发者 https://www.devze.com 2023-03-15 13:44 出处:网络
http://pastebin.com/raw.php?i=7NTGXU5R I have about a hundred of those listened in the same file I tried working on a php solution, but I wasn\'t sure how to parse the sp开发者_运维问答ace, I could

http://pastebin.com/raw.php?i=7NTGXU5R

I have about a hundred of those listened in the same file

I tried working on a php solution, but I wasn't sure how to parse the sp开发者_运维问答ace, I could only find fgetcsv which does commas

What direction should I head to in order to make sense

I remember some C++ from years ago, I was thinking I do something like a getline, then store the line (or row in our case) into an array Once that is done, just write a bunch of if statements to go through each line and classify the first element (column) in each array to be the designated 'header'.


Tasks like that always boil down to a large amount of custom string-munching code. Your best weapons of choice will be regular expressions. Forget about fgetcsv if files look like your file does.

The basic logic might look something like this:

  • Fetch all rows of the file via the file function.
  • Save each table area to an own array containing the rows:
foreach ($filelines as $line)
{
    $lefreportlines[] = trim(substr($line, 0, 93));
    $middlereportlines[] = trim(substr($line, 67, 135));
    ...
}
  • When you're done, start processing each report as it deserves. For example, the leftmost report might simply be parsed with preg_split('/\s+/', $line);

Either way, you'll have a lot of work to do. Good luck!

0

精彩评论

暂无评论...
验证码 换一张
取 消