473,320 Members | 1,857 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

parsing and displaying a text file

Hello all, I am having a problem displaying a txt file I have. I have code to parse it but I do not know how to display the information.

The code I have is:
[PHP]<?php
// Process server data
if ( $fdsStatusTXT = file_get_contents ( "fdsstatus.txt" ) )
{
$fdsStatusArray = explode ( "\n", $fdsStatusTXT );
// Create gameData array
$gameData = array (
'mode' => $fdsStatusArray[0],
'map' => $fdsStatusArray[1],
'gdi_players' => $fdsStatusArray[2],
'gdi_points' => $fdsStatusArray[3],
'nod_players' => $fdsStatusArray[4],
'nod_points' => $fdsStatusArray[5],
'max_players' => $fdsStatusArray[6],
'timeleft' => $fdsStatusArray[7],
'sfps' => $fdsStatusArray[8]
);

// Create playerData array
for ( $i = 0; $i < $gameData['gdi_players']+$gameData['nod_players']; $i++ )
{
// Explode the appropriate index of $fdsStatusArray into itself
$fdsStatusArray[$i+9] = explode ( "\t", $fdsStatusArray[$i+9] );

// Adjust time field
$fdsStatusArray[$i+9][6] = substr ( $fdsStatusArray[$i+9][6], strpos( $fdsStatusArray[$i+9][6], "." )+1 );
$playerData[$i] = array (
'name' => trim($fdsStatusArray[$i+9][0]),
'side' => trim($fdsStatusArray[$i+9][1]),
'score' => trim($fdsStatusArray[$i+9][2]),
'kills' => trim($fdsStatusArray[$i+9][3]),
'deaths' => trim($fdsStatusArray[$i+9][4]),
'ping' => trim($fdsStatusArray[$i+9][5]),
'time' => trim($fdsStatusArray[$i+9][6])
);
}
}
?>[/PHP]
Jan 19 '08 #1
3 1302
Atli
5,058 Expert 4TB
Hi. Welcome to TSDN!

You may want to take a look at the print_r() function. It's good if you only want to see the contents of an array without any fancy tables and such.

I'm not really sure what you want to do with all that information there.
The code you posted will parse it into arrays, the only thing you would have to do is print it into whatever format you want to view it in.

If you give us a little more info on what exactly you are trying to do, and maybe how much PHP experience you have, we may be able to give you more helpful answers.
Jan 19 '08 #2
I have some phh experience (2 years self taught) and I want to display this in 2 ways: one in a php page that will just display the info (tables not needed) and one in a php page that acts as an image.
Jan 20 '08 #3
Atli
5,058 Expert 4TB
Ok.

If you just want the info, nothing fancy, in your PHP page, just do something like this:
Expand|Select|Wrap|Line Numbers
  1. echo "<pre>". print_r($myArray, true) ."</pre>";
  2.  
To put it into an image, you would probably want to use the Image Functions. Check out the example on the page there. You probably want something similar to that.
Jan 21 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Joe Price | last post by:
Hi chaps I've got an XML file, within that file i've embedded html code using the <!]> tag I'm displaying that xml file through a browser using an xsl style sheet. However it is displaying...
4
by: ralphNOSPAM | last post by:
Is there a function or otherwise some way to pull out the target text within an XML tag? For example, in the XML tag below, I want to pull out 'CALIFORNIA'. ...
3
by: Pir8 | last post by:
I have a complex xml file, which contains stories within a magazine. The structure of the xml file is as follows: <?xml version="1.0" encoding="ISO-8859-1" ?> <magazine> <story>...
2
by: Andy | last post by:
Hi guys, I'm writing a program with a feature of accepting user input as command text and parsing it to correct function calls...example: "5 minutes later"/"5 min later"/"5 minute...
3
by: toton | last post by:
Hi, I have some ascii files, which are having some formatted text. I want to read some section only from the total file. For that what I am doing is indexing the sections (denoted by .START in...
6
by: sukiu47 | last post by:
I have one text file . I having a problem to read multiple lines in text file my Text file A { A20 = { { 11, 32, 96, 33, 28 }, { 22, 23, 45, 23, 22 },
13
by: Chris Carlen | last post by:
Hi: Having completed enough serial driver code for a TMS320F2812 microcontroller to talk to a terminal, I am now trying different approaches to command interpretation. I have a very simple...
2
by: nicky123 | last post by:
Hi everyone, This is a brief description that I have provided for parsing & displaying an XML document using DOM API. Please feel free to post your own comments & views regarding...
1
by: avpkills2002 | last post by:
I seem to be getting this weird problem in Internet explorer. I have written a code for parsing a XML file and displaying the output. The code works perfectly fine with ffx(Firefox).However is not...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.