TUSClan.com Message Board  
Go Back   TUSClan.com Message Board > Computer Help Desk > Ask Your Webpage Questions
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
Old 06-05-2007, 04:11 PM   #1
Evan
Senior Member
 
Evan's Avatar
 
Join Date: Sep 2001
Location: Connecticut
Posts: 1,389
Thanks: 10
Thanked 48 Times in 27 Posts
You can not vote!
0
You can not vote!

PHP question (txt parsing)

I have two text documents that I am attempting to parse and pull out certain information which will then be sent to a ms access database. I have been attempting to do this in vb .net but realized that it might be easier to do it in php.

Below is the text document that I am attempting to parse:
Code:
1000 ! TRANSFER ALLOCATION FILE
1010 ! CREATED BY PACER MNAV ON 030805 AT TIME  10:48:30am  BY FMC167  
1020 ! FOR COMPONENT TOTASSET
1030 BASIS, CLOSE 
1040 DATE = 030804
1050 AKCAS   ,                   20427243.96
1060 AKE00   ,                   65177994.91
1070 AKF00   ,                    -767413.80
1080 AKF01   ,                    4579703.40
1090 AKI00   ,                   79102661.65
1100 AKI01   ,                   11535019.04
1110 AKU00   ,                   -6025669.51
1120 AKU01   ,                   -1425595.10
1130 AKU02   ,                    3022089.37
1140 AKU03   ,                    8413147.24
1150 AKU04   ,                     512975.30
I have to pull out the date int (030804), the list of stings that start with "AK", and the list of decimal values.

From here, I have to insert this information into ms access tables. Ideally I would want to pull out the three types of information I need and store it as three separate arrays.

Can anybody point me in the right directions regarding parsing text files in PHP and pulling out the information I need. Any help would be greatly appreciated.
Evan is offline   Reply With Quote Share on facebook Share on Facebook
Old 06-06-2007, 12:45 AM   #2
jetnet
Administrator
 
jetnet's Avatar
 
Join Date: Dec 2000
Location: Texas
Posts: 14,558
Thanks: 155
Thanked 2,921 Times in 1,074 Posts
Send a message via AIM to jetnet Send a message via Yahoo to jetnet
Re: PHP question (txt parsing)

Here ya go:

Code:
<?
$handle = fopen('sample.txt','r');
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
    $num = count($data);
    $row++;
    for ($c=0; $c < $num; $c++) {
        $data[$c] = trim($data[$c]);
        ereg("^([0-9]{4}) ([A-Z0-9]{5})",$data[$c],$regex);
        if ($regex[2] && $regex[2] != "BASIS")
        {
                echo $regex[2] ." = ";
        }
        elseif (ereg("^[0-9]{4} DATE = ([0-9]{6})",$data[$c],$date))
        {
                echo "date=" . $date[1] . "\n";
        }
        elseif (ereg("^-?[0-9]{6,}",$data[$c]))
        {
                echo $data[$c] . "\n";
        }

        unset($regex, $date);
        $varname = $data[$c];
    }
}
?>
jetnet is offline   Reply With Quote Share on facebook Share on Facebook
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[Digg] PHP and RSS: Getting it together Tusbot Absolute News 0 12-08-2006 06:53 AM
[Digg] Symfony PHP Framework 1.0 Beta Released! Tusbot Absolute News 0 11-29-2006 03:10 PM
question for jet, regarding sessions with PHP kows Ask Your Webpage Questions 1 10-29-2006 09:41 AM
Extending and Embedding PHP jetnet Absolute News 0 07-31-2006 03:51 PM
Lead PHP Developer Quits jetnet Absolute News 0 07-28-2006 07:53 AM


All times are GMT -5. The time now is 06:31 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
Powered By localLINUX, Inc.