Author |
Message |
Dawg
RavenNuke(tm) Development Team

Joined: Nov 07, 2003
Posts: 928
|
Posted:
Sat Jun 10, 2006 7:43 am |
|
I have a text file....
Expires:200606071930;;270616
FZUS52 KILM 070736
CWFILM
COASTAL WATERS FORECAST
NATIONAL WEATHER SERVICE WILMINGTON NC
336 AM EDT WED JUN 7 2006
SURF CITY NC TO SOUTH SANTEE RIVER SC OUT 20 NM
AMZ250-252-071930-
/O.ROU.KILM.MA.F.0000.000000T0000Z-000000T0000Z/
SURF CITY TO CAPE FEAR NC OUT 20 NM-
CAPE FEAR NC TO LITTLE RIVER INLET SC OUT 20 NM-
336 AM EDT WED JUN 7 2006
.TODAY...NW WINDS 10 TO 15 KT BECOMING SW. SEAS 2 TO 3 FT.
.TONIGHT...SW WINDS 10 TO 15 KT. SEAS 2 TO 4 FT.
.THU...SW WINDS 15 TO 20 KT. SEAS 3 TO 5 FT. A CHANCE OF SHOWERS
AND TSTMS IN THE AFTERNOON.
.THU NIGHT...SW WINDS 15 TO 20 KT BECOMING W. SEAS 3 TO 5 FT. A
CHANCE OF SHOWERS AND TSTMS.
.FRI...W WINDS 15 TO 20 KT...DIMINISHING TO 10 TO 15 KT. SEAS
SUBSIDING TO 2 TO 3 FT. A SLIGHT CHANCE OF SHOWERS AND TSTMS IN THE
AFTERNOON.
.FRI NIGHT...W WINDS 10 KT...BECOMING NW. SEAS 2 TO 4 FT.
.SAT...NW WINDS 5 TO 10 KT...BECOMING SW. SEAS 2 TO 3 FT.
.SUN...NW WINDS 5 TO 10 KT...BECOMING SW. SEAS 2 TO 3 FT.
MARINERS ARE REMINDED THAT WINDS AND SEAS CAN BE HIGHER IN AND
NEAR THUNDERSTORMS.
I have cut all the crud out of it......
Code:$weather_data = file_get_contents('cache/amz252_TEST.txt');
// Keep everything after '_'
$page = strstr($weather_data,'/O.ROU.KILM.MA.F.0000.000000T0000Z-000000T0000Z/');
// Find where we start to display
$table_start = strpos($page, 'SURF CITY');
// Find where to stop the display
$table_end = strpos($page, ' ');
// And print a slice of $page that holds the data
$test = substr($page, $table_start, $table_end - $table_start);
echo $test;
|
$test echos out ....
SURF CITY TO CAPE FEAR NC OUT 20 NM- CAPE FEAR NC TO LITTLE RIVER INLET SC OUT 20 NM- 336 AM EDT WED JUN 7 2006 .TODAY...NW WINDS 10 TO 15 KT BECOMING SW. SEAS 2 TO 3 FT. .TONIGHT...SW WINDS 10 TO 15 KT. SEAS 2 TO 4 FT. .THU...SW WINDS 15 TO 20 KT. SEAS 3 TO 5 FT. A CHANCE OF SHOWERS AND TSTMS IN THE AFTERNOON. .THU NIGHT...SW WINDS 15 TO 20 KT BECOMING W. SEAS 3 TO 5 FT. A CHANCE OF SHOWERS AND TSTMS. .FRI...W WINDS 15 TO 20 KT...DIMINISHING TO 10 TO 15 KT. SEAS SUBSIDING TO 2 TO 3 FT. A SLIGHT CHANCE OF SHOWERS AND TSTMS IN THE AFTERNOON. .FRI NIGHT...W WINDS 10 KT...BECOMING NW. SEAS 2 TO 4 FT. .SAT...NW WINDS 5 TO 10 KT...BECOMING SW. SEAS 2 TO 3 FT. .SUN...NW WINDS 5 TO 10 KT...BECOMING SW. SEAS 2 TO 3 FT. MARINERS ARE REMINDED THAT WINDS AND SEAS CAN BE HIGHER IN AND NEAR THUNDERSTORMS.
Now I want to Explode it by the '.' and loop back through and echo the results.
Code:$test2 = explode(".", $test);
// $lineCount = count($test2);
echo $test2;
// for ($i = 0; $i < $lineCount; $i++){
// echo $lines[$i]."<hr>";
|
All I am getting from $test2 is 'array' and I do not understand why....I suspect I am doing something dumb and have sat in my chair to long.
A nudge in the correct direction is all that is needed.
Thank You for the help!
Dawg [/code] |
|
|
|
 |
kguske
Site Admin

Joined: Jun 04, 2004
Posts: 6437
|
Posted:
Sat Jun 10, 2006 9:00 am |
|
The explode command makes $test2 an array, which can't be echoed directly.
If you want to see what's in the array, use print_r instead of echo. Or, you could use echo $test2[0] to show what's in line 1... |
_________________ I search, therefore I exist...
Only registered users can see links on this board! Get registered or login! |
|
|
 |
Dawg

|
Posted:
Sat Jun 10, 2006 10:50 am |
|
K,
Thank You for your help. That send me down the right path....Thank You!
I am getting REAL close to what I am looking for now. Did I meantion I HATE parseing Text files. It always SUX!
Code:$newline = "<br />";
$weather_data = file_get_contents('cache/amz252_TEST.txt');
// Keep everything after '_'
$page = strstr($weather_data,'/O.ROU.KILM.MA.F.0000.000000T0000Z-000000T0000Z/');
// Find where we start to display
$table_start = strpos($page, 'SURF CITY');
// Find where to stop the display
$table_end = strpos($page, ' ');
// And print a slice of $page that holds the table
$test = substr($page, $table_start, $table_end - $table_start);
//echo $test;
$test2 = explode(".", $test);
//print_r ($test2);
foreach ($test2 as $v) {
echo "$v.$newline";
|
This has me REAL close....
Here is the output.
SURF CITY TO CAPE FEAR NC OUT 20 NM- CAPE FEAR NC TO LITTLE RIVER INLET SC OUT 20 NM- 336 AM EDT WED JUN 7 2006 .
TODAY.
.
.
NW WINDS 10 TO 15 KT BECOMING SW.
SEAS 2 TO 3 FT.
.
TONIGHT.
.
.
SW WINDS 10 TO 15 KT.
SEAS 2 TO 4 FT.
.
THU.
.
.
SW WINDS 15 TO 20 KT.
SEAS 3 TO 5 FT.
A CHANCE OF SHOWERS AND TSTMS IN THE AFTERNOON.
.
THU NIGHT.
.
.
SW WINDS 15 TO 20 KT BECOMING W.
SEAS 3 TO 5 FT.
A CHANCE OF SHOWERS AND TSTMS.
.
FRI.
.
.
W WINDS 15 TO 20 KT.
.
.
DIMINISHING TO 10 TO 15 KT.
SEAS SUBSIDING TO 2 TO 3 FT.
A SLIGHT CHANCE OF SHOWERS AND TSTMS IN THE AFTERNOON.
.
FRI NIGHT.
.
.
W WINDS 10 KT.
.
.
BECOMING NW.
SEAS 2 TO 4 FT.
.
SAT.
.
.
NW WINDS 5 TO 10 KT.
.
.
BECOMING SW.
SEAS 2 TO 3 FT.
.
SUN.
.
.
NW WINDS 5 TO 10 KT.
.
.
BECOMING SW.
SEAS 2 TO 3 FT.
MARINERS ARE REMINDED THAT WINDS AND SEAS CAN BE HIGHER IN AND NEAR THUNDERSTORMS.
.
My next task is to pick out the FRI SAT...days of the week stuff and bold them so it sticks out a little more.
That is my next task.....this is my next question....
While this seems to work just fine....it seems pretty slow to run. I will put a timer on it later. My question is ....Am I going about this the right way? This is for a mouseover map with about 15 sections (forecasts) in it. If each one of these takes 2-3 seconds to parse....it will take the whole thing 30 secs. That is not going to work. What do you think? Am I going about this the right way? |
|
|
|
 |
kguske

|
Posted:
Sat Jun 10, 2006 11:03 am |
|
Probably the most efficient way would be to get it either as a SOAP service or RSS feed - that way you wouldn't have to do all the parsing. But if that's not available, you're on the right track. You can compare various PHP command at php.net to find the most efficient. There are often really good suggestions by people at the bottom of each command explanation, too. |
|
|
|
 |
Dawg

|
Posted:
Sat Jun 10, 2006 11:24 am |
|
K,
There are Feeds availible. I know nothing about SOAP and very little about RSS. I struggle with PHP and Javascript so I have taken a "Go with What you Know" approach. I will do some reading as I pull all of this together.
My guess is that if this takes too long to run, I will include the code in the script that caches the file and that way it runs in the background and the end users never see it and the Map just reads the txt file from cache.
Dawg |
|
|
|
 |
kguske

|
Posted:
Sat Jun 10, 2006 11:32 am |
|
If there's an RSS feed, you can add it as a block. That would be the simplest way AFAIK. SOAP is more complicated. But there's nothing wrong with "Go With What You Know"! |
|
|
|
 |
Dawg

|
Posted:
Sat Jun 10, 2006 11:40 am |
|
That kind of BLOCK is not what I am looking for.
I will send you a link vie PM....The map about half way down the front page with the mouseover is what I am working on. My plan is to Make that a Tabbed map Current Conitions on top...then Forecast...then Radar...then a custom inhosue forecast map. All done with javascript mouseover. It should be pretty cool when I get done.
Dawg |
|
|
|
 |
kguske

|
Posted:
Sat Jun 10, 2006 3:48 pm |
|
Nice. Keep up the good work... |
|
|
|
 |
|