Reply
Help needed to insert dynamic information from an online text file and other things
Old 10-31-2009, 02:18 AM Help needed to insert dynamic information from an online text file and other things
Novice Talker

Posts: 13
Name: Eric
Trades: 0
Hey,

I am relatively new to this game, I would call myself a beginner with some strong problem solving skills. So bear with me...

My website is http://www.paddlingabc.com. It is an online guide to whitewater rivers using google earth, youtube, etc. Two key things for paddlers are weather and river levels. On the main page you will see in the right hand side bar I have listed river gauges and weather for a wide variety of rivers and areas. The river levels are currently just links to seperate webpages. This same information is stored in a publicly available text file that is updated about every 20minutes by environment canada. I would like to display the latest water levels for rivers directly on my webpage rather than a link to the information. Is this possible with PHP? Do I need to do something else?

You will also notice that there is current weather displayed for a bunch of different geograhic areas.

I would like to change all of this so that there is a drop down selection box with geographic areas in it along with a check box to remember the user selection. When a used selects their geopgraphic area I would like it to display the current weather and relevant river levels for them. Is this possible? Is this done using HTML?

Any links to tutorials or help would be greatly appreciated!

Eric
erich1 is offline
Reply With Quote
View Public Profile
 
 
When You Register, These Ads Go Away!
Old 10-31-2009, 04:23 AM Re: Help needed to insert dynamic information from an online text file and other thin
JeremyMiller's Avatar
Full-Time TeraTasker

Posts: 1,470
Name: Jeremy Miller
Location: Marianna, FL
Trades: 0
Here's the pseudocode to get you started. If you get stuck, post the code for the spot you're having trouble with and we'll see what we can do.
Code:
IF (current cache of selected file does not exist OR file is older than 20 minutes)
THEN Fetch selected file and cache locally

FOREACH (line in the cache for the selected file)
  IF (line is formatted as a line to read [there are many ways to define this])
    Split into an array and output formatted data.
  END IF
END FOREACH
You'd have a selector for the user to choose their desired geographic area (and perhaps choose one as a default).

I hope that gets you started. Let us know how it goes.
__________________
Jeremy Miller - TeraTask
Content Farmer - Automated Posting for Content & Blog Sites
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 10-31-2009, 11:53 AM Re: Help needed to insert dynamic information from an online text file and other thin
Novice Talker

Posts: 13
Name: Eric
Trades: 0
I understand those basic principles but know nothing really about coding in php. I would imagine this would be a common task for things like sports scores or something. Is there any kind of tutorial I can follow somewhere and then edit on my own accord for my needs.

I tried briefly to do this myself using so getfile commands and trying to move the pointer to the end of the file. No luck.
erich1 is offline
Reply With Quote
View Public Profile
 
Old 11-04-2009, 11:48 PM Re: Help needed to insert dynamic information from an online text file and other thin
Novice Talker

Posts: 13
Name: Eric
Trades: 0
ALrighht I figured out the selection box thing but still need help on loading information from a text file using php.

I have tried the fopen command and SSI. I do not know how to get the information in. Basically I want to gather the info on the last line of the following text file http://http://www.environment.albert...CATAFOR-WL.txt

I want this so my webpage loads this file every time as the water level information changes frequently in this text file.
erich1 is offline
Reply With Quote
View Public Profile
 
Old 11-05-2009, 12:45 PM Re: Help needed to insert dynamic information from an online text file and other thin
Novice Talker

Posts: 13
Name: Eric
Trades: 0
Code:
<?php
$file = "http://www.environment.alberta.ca/forecasting/data/hydro/tables/BOW-RCATAFOR-WL.txt";
$f = fopen($file, "r");

while ( 
$line = fgets($f, 10) ) 

{
print $line;
}
Tried this and it prints out a bunch of the text file. I just want a portion of the data though. I tried to put fseek in here and it didnt do anything. At least now it is displaying the text file on the webpage but I want to display just a small portion of this text file. How do I do that and specify the portion?
erich1 is offline
Reply With Quote
View Public Profile
 
Old 11-05-2009, 04:36 PM Re: Help needed to insert dynamic information from an online text file and other thin
JeremyMiller's Avatar
Full-Time TeraTasker

Posts: 1,470
Name: Jeremy Miller
Location: Marianna, FL
Trades: 0
Take a look at this (I took the base fgets code from the PHP site and modified it to only print the last line):

PHP Code:
<?php
$file 
"http://www.environment.alberta.ca/forecasting/data/hydro/tables/BOW-RCATAFOR-WL.txt";
$handle = @fopen($file"r");
if (
$handle) {
    while (!
feof($handle)) {
        
$buffer fgets($handle);
    }
    
fclose($handle);
    echo 
$buffer;
}
?>
__________________
Jeremy Miller - TeraTask
Content Farmer - Automated Posting for Content & Blog Sites
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 11-05-2009, 07:20 PM Re: Help needed to insert dynamic information from an online text file and other thin
Novice Talker

Posts: 13
Name: Eric
Trades: 0
Thanks so much worked perfectly!
erich1 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Help needed to insert dynamic information from an online text file and other things
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 



Page generated in 0.41561 seconds with 13 queries