Jump to content

Recommended Posts

I want to create a program that will read a .txt file

and pull the needed information out do whatever

calucalations and then display it to the screen.

 

What will be the first thing that I will need or do?

 

1. Read .txt file.

2. Calucalation.

3. Display to user screen.

 

Example of the file.

-Do not reply to this email-

Here are the official results of your Madden NFL 07 game on 2007.5.10-16:07:08.

Mode: Hardcore Ranked
Qtr Length: 4 minutes
Difficulty: All-Madden
Opponent: jewish 786
Rank: 9113

Score breakdown:

                    1    2    3    4   OT    F
Trium918            7   13    7    3    0   30
jewish 786          6   14    0    7    0   27

Statistics                  Trium918          jewish 786      
Rushing attempts for                 19              14
Rushing yards for                    95              57
Passing attempts for                 30              19
Passing yards for                   276             119
Punts                                 0               0
Field goals for                       3               0
Long field goals (40+) for            1               0
Rushing touchdowns for                1               2
Passing touchdowns for                2               0
Returns touchdowns for                0               1
Defensive touchdowns for              0               0
Turnovers for                         2               2
Interceptions for                     2               1
Sacks for                             1               3
Number of third downs                 7               7
Third down conversions                3               2
No-huddle plays                      16               4
Audibles called                      20               1
Hot routes used                      27              20
Shotgun plays                         4               6
Blitzes                               5              38
Time of possession                 9:49            6:11
2-point conversions tried             0               0
2-point conversions succeeded         0               0
Red zone field goals                  2               0
Red zone touchdowns                   3               2
Red zone opportunities                5               2
First downs                          20               7
First down yards                    154              66
Special teams yards                 113             233
Punt return yards                     0               0
Punt yards                            0               0
Penalties                             3               1
Penalty yards                        20               5
First down rushing plays             11               9
First down passing plays             15               4
Second down rushing plays             6               4
Second down passing plays            11               6
Third down rushing plays              2               1
Third down passing plays              5               6
Fourth down rushing plays             0               0
Fourth down passing plays             2               4
Passes completed                     19               6
Fumbles                               1               0
Fumbles recovered                     0               0
Possessions                          13              12
Third downs, 3 or less yards          3               0
  Successes                           2               0
Third downs, 4 to 9 yards             2               4
  Successes                           0               1
Third downs, 10 or more yards         2               3
  Successes                           1               1
Hurries                               7               6
Knockdowns                            3               1
Passes deflected                      6               3
Passes tipped                         0               0
Offensive yards                     371             176
Total yards                         484             409
Return yards                        113             233
Total touchdowns                      3               3


If you believe you are not the intended recipient of this message, or this message contains rude and offensive content, please contact Electronic Arts immediately. To report this issue visit http://eamembers.custhelp.com/cgi-bin/eamembers.cfg/php/enduser/std_adp.php?%20p_faqid=14885 .

PRIVACY POLICY:  Our ESRB Privacy Online Certified Policy gives you confidence whenever you play EA games.  To view our complete Privacy Policy, go to www.ea.com/global/legal/privacy.jsp.

-------------------------------
EA SPORTS™
http://www.EASPORTS.com

Link to comment
https://forums.phpfreaks.com/topic/50851-what-are-some-options/
Share on other sites

You'll need to write a class that will parse, process, and determine what data it pulled from that text file. Assuming of course, the text files will always be in the exact same format. If not, you'd have to take into account any variations when you write your code. Once you can properly parse/read the data properly...you can move on to the next steps.

Link to comment
https://forums.phpfreaks.com/topic/50851-what-are-some-options/#findComment-250104
Share on other sites

You'll need to write a class that will parse, process, and determine what data it pulled from that text file. Assuming of course, the text files will always be in the exact same format. If not, you'd have to take into account any variations when you write your code. Once you can properly parse/read the data properly...you can move on to the next steps.

 

Exactly, what do you mean about class?

Link to comment
https://forums.phpfreaks.com/topic/50851-what-are-some-options/#findComment-250110
Share on other sites

You don't have to write a class if you do not know OOP. A class would be nice but not necessary.

 

You would just need a series of functions, one that parses out the data another that takes the parsed data and processes it.

 

The first step though is reading the data into a string or array. I like strings better for parsing but that is just me.

 

Second you need to find the data you want and put them into seperate variables using known and common keys as to say. This might help you on your way:

 

<?php
$file = file('textfile.txt');

list($first,$modes) = spliti('mode:', $file);
list($modes, $scores) = spliti('score', $modes);
list($scores, $stats) = spliti('statistics', $scores);
list($stats, $end) = spliti('If you believe', $stats);
?>

 

Hopefully they gets you started alright.

Link to comment
https://forums.phpfreaks.com/topic/50851-what-are-some-options/#findComment-250123
Share on other sites

You don't have to write a class if you do not know OOP. A class would be nice but not necessary.

 

You would just need a series of functions, one that parses out the data another that takes the parsed data and processes it.

 

The first step though is reading the data into a string or array. I like strings better for parsing but that is just me.

 

Second you need to find the data you want and put them into seperate variables using known and common keys as to say. This might help you on your way:

 

<?php
$file = file('textfile.txt');

list($first,$modes) = spliti('mode:', $file);
list($modes, $scores) = spliti('score', $modes);
list($scores, $stats) = spliti('statistics', $scores);
list($stats, $end) = spliti('If you believe', $stats);
?>

 

Hopefully they gets you started alright.

 

Someone help me out here. I am trying to get a

better understanding of what is going on with the

script below. Read comments a

 

<?php

// Reads entire file into an array
$file = file('textfile.txt');

/* Ok the list() part is sort of tricky.
For instance, the first line code I am asuming that 
it is suppose to display the 

Mode: Hardcore Ranked 

from the text file. I tried to echo it, but I am getting nothing.
What am I doing wrong?
*/
list($first,$modes) = spliti('mode:', $file);

?>

Link to comment
https://forums.phpfreaks.com/topic/50851-what-are-some-options/#findComment-250146
Share on other sites

Shit my bad man, try it this way:

 

<?php
$file = file_get_contents('textfile.txt');

list($first,$modes) = spliti('mode:', $file);
list($modes, $scores) = spliti('score', $modes);
list($scores, $stats) = spliti('statistics', $scores);
list($stats, $end) = spliti('If you believe', $stats);
?>

 

I was giving you the array version when I wanted to give you the string (file_get_contents returns string file returns array)

 

My bad man.

Link to comment
https://forums.phpfreaks.com/topic/50851-what-are-some-options/#findComment-250154
Share on other sites

Ok, now I am getting some output.

I want to know is this the create way

or not?

 

<?php 
# I am calling it like this from
list($modes, $scores) = spliti('score', $modes);
echo "$modes $scores"."<br />"; 
?>
Hardcore Ranked Qtr Length: 4 minutes Difficulty: All-Madden Opponent: jewish 786 Rank: 9113 breakdown: 1 2 3 4 OT F Trium918 7 13 7 3 0 30 jewish 786 6 14 0 7 0 27 

 

I am looking for this format!

Mode: Hardcore Ranked
Qtr Length: 4 minutes
Difficulty: All-Madden
Opponent: jewish 786
Rank: 9113

Score breakdown:

                    1    2    3    4   OT    F
Trium918            7   13    7    3    0   30
jewish 786          6   14    0    7    0   27

Link to comment
https://forums.phpfreaks.com/topic/50851-what-are-some-options/#findComment-250171
Share on other sites

Seems like you are on the right track to me.

 

One side note though, when you split that word is essentially "removed". You may want to do this:

 

<?php 
# I am calling it like this from
list($modes, $scores) = spliti('score', $modes);
echo "Mode: $modes Score $scores"."<br />"; 
?>

 

Just an FYI.

Link to comment
https://forums.phpfreaks.com/topic/50851-what-are-some-options/#findComment-250172
Share on other sites

None what I use

<?php
$fp = fopen("textfile.txt", "r");
?>

In order to read the file line by line to get the

format below?


Mode: Hardcore Ranked
Qtr Length: 4 minutes
Difficulty: All-Madden
Opponent: jewish 786
Rank: 9113

Score breakdown:

                    1    2    3    4   OT    F
Trium918            7   13    7    3    0   30
jewish 786          6   14    0    7    0   27

Link to comment
https://forums.phpfreaks.com/topic/50851-what-are-some-options/#findComment-250177
Share on other sites

Ok, my question is this. Do I need both scripts that

frost110 provided?

 

From what I understand I will need

<?php 
# I am calling it like this from
list($modes, $scores) = spliti('score', $modes);
echo "Mode: $modes Score $scores"."<br />"; 
?>

to asign variables and

<?php
$file = file('textfile.txt');

foreach ($file as $line) {
    echo $line . '<br />';
}
?>

to read the entire file.

 

Link to comment
https://forums.phpfreaks.com/topic/50851-what-are-some-options/#findComment-250202
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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