PDA

View Full Version : Reading values form an HTML file


lux
12-06-2006, 01:24 PM
Hey people,

Does anyone know how i can read a value from an html file that is automatticly generated from an application and use it in a variable in a php script on another page?

davidj
12-06-2006, 02:55 PM
Does anyone know how i can read a value from an html file that is automatticly generated from an application and use it in a variable in a php script on another page?

what are you trying to do

i have processes creating CSV's which i use PHP to read each line and perform a db insert. Is this the kind of thing you want

lux
12-06-2006, 04:49 PM
Reading back what I wrote leaves me thinking I really am crap at explaining myself!

Im rebuilding a basketball website. As part of the match reports i will be displaying statistical information from the games. This info will be generated by an application which sits on a laptop, used by someone at the game. when the game finishes the app produces an html page which details the game stats. This includes everything from who played how many minutes to the number of steals and rebounders by each player etc.

Because the basketball web site caters for three teams that each play in excess of 25 games a second I really donít want to create a mammoth form where all this info is entered by the user as the time it would take would be beyond the benefits of doing it in the first place.

What I would like to do is somehow read from the html file generated by the app the values I want to display on my site and pass them to my "match reports.php" page where I will display them the way I want to.

Hope this explanation is a bit more clear, if not please shout back at me! haha

davidj
12-06-2006, 05:06 PM
If your wanting to process this data then i am assuming that this file is uploaded to your server?

if this is the case then why not just call the page in an iframe and just apply some CSS

lux
12-06-2006, 05:39 PM
yes the first thing that will happen is the file is uploaded to the server, to a specified folder.

i wanted to manipulate the data with php to produce a nice coloured bar to show percentages(which i have already created). at the moment the site just links to the sheet which open in a new tab/window, which is a bit boring.

I was aiming for a display like the bbc use of football match stats. like i said i can display the info fine, but its getting the info from the html into the page that manipultes the data which is the difficult bit!

domedia
12-06-2006, 06:38 PM
If you already have the data in your DB, just echo it directly to your page. This suggestion is so simple that I think there's something you're not telling us. :)

Or is all this data on a website/server you don't have access to?

davidj
12-06-2006, 06:39 PM
can you post an example of the html file

davidj
12-06-2006, 06:40 PM
If you already have the data in your DB, just echo it directly to your page

its not coming from his db its created from a different independent process

davidj
12-06-2006, 07:24 PM
got it!

first create a html file called table.html...


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<table width="290" height="239" border="1">
<tr>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
<td>4</td>
<td>5</td>
<td>6</td>
</tr>
<tr>
<td>2</td>
<td>3</td>
<td>4</td>
<td>3</td>
<td>2</td>
<td>4</td>
<td>2</td>
</tr>
<tr>
<td>22</td>
<td>33</td>
<td>4</td>
<td>444</td>
<td>4</td>
<td>44</td>
<td>55</td>
</tr>
<tr>
<td>11</td>
<td>1</td>
<td>11</td>
<td>2</td>
<td>22</td>
<td>2</td>
<td>99</td>
</tr>
<tr>
<td>88</td>
<td>8</td>
<td>7</td>
<td>66</td>
<td>55</td>
<td>55</td>
<td>5</td>
</tr>
</table>
</body>
</html>


now here is your php file


<?php
$myFile = "table.html";
$fh = fopen($myFile, 'r');
$theData = fread($fh, filesize($myFile));
fclose($fh);
$html ='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>';
$html2 ='</body>
</html>';

$tableStrip = str_replace($html, '', $theData);
$tableStrip2 = str_replace($html2, '', $tableStrip);

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<?php echo $tableStrip2; ?>
</body>
</html>


$html & $html2 contain html from your html file that you need to strip out using str_replace() so your just left with the full <table

you are left with $tableStrip2; which echos the table

lux
12-06-2006, 07:34 PM
ive attached the html page thats generated by an external application (not web based)

so yeah..i want to read the info from the file to display like this:

http://www.nba.com/games/20061205/DALNJN/gameinfo.html?nav=scoreboardhome

specifically the stats at a glance part.

like i said i could have the user input the data again but its just so time consuming, and unfortunatly he cant output the data to a xml file which would be a lot easier!!!! ahhhhh

does that help? haha

davidj
12-06-2006, 07:53 PM
looking at your example you just need to set

$html ='<HTML>
<HEAD><TITLE>Game Box Score</TITLE></HEAD>
<BODY bgcolor="FFFFFF" text="000000" link="0000FF" vlink="871F78">
<center>';

and


$html2='</center></BODY>
</HTML>';


you could use str_replace() to strip out the formating in the tables

lux
12-06-2006, 08:02 PM
and include() the file in my matchreports.php page and use the variable, i see.

so a little bit of formatting to the generated stats page and im there, cool.

i may try to write a function (haha) to strip out the stuff i dont want! would be cool.

lux
12-06-2006, 08:03 PM
oh shite sorry, didnt say thanks dj.

davidj
12-06-2006, 08:03 PM
no probs

you just keep me on my toes

lux
12-06-2006, 08:16 PM
haha,

i'm thinking the forum members should start taking bets on how long it will be before i manage to answer my question and someone understand within one page due to my strange ways in explaining my point! hehe

also how do you do smilies on here?

davidj
12-06-2006, 08:20 PM
oh yes

you normal people only have a basic text editor while me (being royalty) have super mega advanced editor at my control

shame but thats life!

lux
12-06-2006, 08:26 PM
damn you and your kind, pheh i spit in your general direction...haha