|
tbweather
|
 |
« on: February 14, 2007, 08:49:39 AM » |
|
I am using a modified version of Carterlake's php script for NOAA warnings and it has been working fine for months. Now, I am suddenly getting 3 extraneous characters added to the beginning of the warning statement. The added characters are different in IE7 and Firefox. IE7 shows "o;?" in front of the warning statement and Firefox shows "". I've looked at the php script and it looks O.K. The html on the htx page that VWS processes doesn't contain the extraneous characters. If I look at the document source code on the page ( http://www.tawasbayweather.com) that is produced after VWS processes the htx file, the characters don't show up. If I just run the php page http://www.tawasbayweather.com/scripts/warning.php it returns the warning without the extra characters. I'm at a loss as to what is happening here. Does anyone have any idea as to what might be causing this? Thanks for any help or advice.
|
|
|
|
|
Logged
|
|
|
|
|
WeatherHost
|
 |
« Reply #1 on: February 14, 2007, 09:38:25 AM » |
|
I see it in Opera on your site, same as you note for FF. Don't see it on mine though, but I've modified CL's script to display different text. Rechecking the source code, I DO see it in there; <td style="color:white; text-align:center"> <b>No current weather advisories</b> in effect for Tawas Bay--- <a href="warningsforecast.htm" style="color:#FFFFFF; text-decoration:none"> Click here for more...
But I don't know were it originates. Maybe something in the php echo command in CL's script?
|
|
|
|
|
Logged
|
|
|
|
|
carterlake
|
 |
« Reply #2 on: February 14, 2007, 10:23:12 AM » |
|
If it's not in the PHP (and we see that it isn't), then it's got to be in the HTML.
|
|
|
|
|
Logged
|
  Davis VP2 6153; Weather Display (LIVE w/ Ajax); Quickcam for Notebooks Pro; Boltek w/ Nexstorm; GRLevel3; live NOAA Radio
|
|
|
|
tbweather
|
 |
« Reply #3 on: February 14, 2007, 11:04:09 AM » |
|
Here is the html for that section of the page: <td style="color:white; text-align:center"> <?php include (" http://www.tawasbayweather.com/scripts/warning.php"); ?> in effect for Tawas Bay--- <a href="warningsforecast.htm" style="color:#FFFFFF; text-decoration:none">Click here for more...</a> I can't see anything that would be adding the extra characters. It's really strange. Looking at the source code in FF, I do see the characters but looking at the source in IE, I don't see the characters.
|
|
|
|
|
Logged
|
|
|
|
|
WeatherHost
|
 |
« Reply #4 on: February 14, 2007, 11:39:05 AM » |
|
<?php include ("http://www.tawasbayweather.com/scripts/warning.php"); ?> I do mine with an Include Virtual statement. <table width="90%" align=center cellpadding=0 cellspacing=0> <tr> <td><!--#include virtual="/advisorynew.php" --></td> </tr> </table>
Where CL's script is on a separate page named 'advisorynew.php' Not sure if that would make a difference or not since you said it had been working until recently. Did your webhost change something? Maybe a new version of php?
|
|
|
|
|
Logged
|
|
|
|
|
carterlake
|
 |
« Reply #5 on: February 14, 2007, 11:50:37 AM » |
|
Upon further testing... it is coming from your PHP script. http://www.carterlake.org/test3.phpWhat's the code look like?
|
|
|
|
|
Logged
|
  Davis VP2 6153; Weather Display (LIVE w/ Ajax); Quickcam for Notebooks Pro; Boltek w/ Nexstorm; GRLevel3; live NOAA Radio
|
|
|
|
|
|
WeatherHost
|
 |
« Reply #7 on: February 14, 2007, 01:54:23 PM » |
|
You say this just started recently.
What, if anything, have you changed recently that might coincide with this problem starting?
|
|
|
|
|
Logged
|
|
|
|
|
tbweather
|
 |
« Reply #8 on: February 14, 2007, 02:16:53 PM » |
|
Weatherhost- I haven't made any changes to the php script but did add the capability to do Google language translations of the main page. After I did that, I noticed the strange characters for the first time. It may have just been coincidence that I first noticed it then because I happened to have been working on the site. I must have done something, but I just can't figure out what it could be.
The echo statement in the php is pretty simple since I am only using the heading on any warnings it is: echo "<b>"; echo $targetwarn; echo "</b>";
Carterlake thinks it is in the php and I believe he is most likely correct. I put the php include statement on a completely new test page and it gave me the same weird characters.
I'll check around on the hosting company's website (Powweb.com) to see if I can determine if they changed the php version. Thanks.
|
|
|
|
|
Logged
|
|
|
|
|
tbweather
|
 |
« Reply #9 on: February 14, 2007, 02:36:32 PM » |
|
I checked the server error log at my web host and this error seems to be recurring:
PHP Warning: implode() [<a href='function.implode'>function.implode</a>]: Bad arguments. in /hermes/web10/b1429/pow.tbweather/htdocs/scripts/warning.php on line 24
Unfortunately, I have no idea what it means???? I think the hosting company uses PHP version 5.
There are other errors but they seem to be related to problems connecting with the NOAA server.
|
|
|
|
|
Logged
|
|
|
|
|
carterlake
|
 |
« Reply #10 on: February 14, 2007, 03:59:15 PM » |
|
If you're using PHP5, try replacing... $html = implode('', file("http://www.crh.noaa.gov/showsigwx.php?warnzone=${warnzone}&warncounty=${warncounty}")); with... $fp = fopen("http://www.crh.noaa.gov/showsigwx.php?warnzone=${warnzone}&warncounty=${warncounty}", "r"); $html =stream_get_contents($fp); (Don't forget to save a backup of the file before you start on it)
|
|
|
|
|
Logged
|
  Davis VP2 6153; Weather Display (LIVE w/ Ajax); Quickcam for Notebooks Pro; Boltek w/ Nexstorm; GRLevel3; live NOAA Radio
|
|
|
|
tbweather
|
 |
« Reply #11 on: February 14, 2007, 04:56:02 PM » |
|
Hmmm... doing that got rid of everything except the weird characters. The error log had this in it:
PHP Fatal error: Call to undefined function: stream_get_contents() in /hermes/web10/b1429/pow.tbweather/htdocs/scripts/warning.php on line 25
I did some more checking and it looks like I have PHP Version 4.4.4. with the ability to change it to Version 5. Sorry about that.
|
|
|
|
|
Logged
|
|
|
|
|
carterlake
|
 |
« Reply #12 on: February 14, 2007, 06:16:22 PM » |
|
That won't work then.... Try... $url = "http://www.crh.noaa.gov/showsigwx.php?warnzone=${warnzone}&warncounty=${warncounty}"; $fp = fopen($url, "r"); while (!feof($fp)){ $html .= fread($fp, 8192);} I'm not sure this is the problem, just trying to eliminate suspects.
|
|
|
|
|
Logged
|
  Davis VP2 6153; Weather Display (LIVE w/ Ajax); Quickcam for Notebooks Pro; Boltek w/ Nexstorm; GRLevel3; live NOAA Radio
|
|
|
|
tbweather
|
 |
« Reply #13 on: February 14, 2007, 06:39:28 PM » |
|
Tom- The script revision works but still produces the extra characters. I put the php testing program on the website so you can see what the web host is providing for php. It's at http://www.tawasbayweather.com/scripts/phptest.php. Thanks.
|
|
|
|
|
Logged
|
|
|
|
|
carterlake
|
 |
« Reply #14 on: February 14, 2007, 06:55:25 PM » |
|
I'm really stumped... it shouldn't be producing those characters. It's definitely something on your host server's setup... I copied the php and executed it... http://www.carterlake.org/test3.phpNo symbols.
|
|
|
|
|
Logged
|
  Davis VP2 6153; Weather Display (LIVE w/ Ajax); Quickcam for Notebooks Pro; Boltek w/ Nexstorm; GRLevel3; live NOAA Radio
|
|
|
|
tbweather
|
 |
« Reply #15 on: February 14, 2007, 07:31:10 PM » |
|
Thanks for your efforts. I will try to track it down with my web host's tech support. They must have changed something to just have this start suddenly when your script has operated flawlessly up til now.
|
|
|
|
|
Logged
|
|
|
|
|
saratogaWX
|
 |
« Reply #16 on: February 14, 2007, 07:44:48 PM » |
|
This was a tough one to solve, but I think I've found how to 'fix' it. I ran the script with error_reporting(E_ALL); set and found the following: Notice: Undefined variable: targetwarn in /homepages/9/d141952417/htdocs/wx/carterlake-warnings.php on line 123
Notice: Undefined variable: targetwarn in /homepages/9/d141952417/htdocs/wx/carterlake-warnings.php on line 126
Notice: Undefined offset: 1 in /homepages/9/d141952417/htdocs/wx/carterlake-warnings.php on line 142
Notice: Undefined offset: 1 in /homepages/9/d141952417/htdocs/wx/carterlake-warnings.php on line 143 To fix the first two, I'd replaced the first IF statement on 123 with a check to see if $targetwarn is empty. Then replaced the compare before the loop with the actual text of what had been set in the previous if statements, so the code looks like this if (empty($targetwarn)) { $targetwarn = "No current weather advisories"; $targettext[0] = "THERE ARE NO ACTIVE WATCHES, WARNINGS OR ADVISORIES"; } else if ($targetwarn == "No Active Hazardous Weather Conditions Found") { $targetwarn = "No current weather advisories"; $targettext[0] = "THERE ARE NO ACTIVE WATCHES, WARNINGS OR ADVISORIES"; } else if ($targetwarn == "Hazardous Weather Outlook") { $targetwarn = "No current weather advisories"; $targettext[0] = "THERE ARE NO ACTIVE WATCHES, WARNINGS OR ADVISORIES"; } else if ($targetwarn == "Short Term Forecast") { $targetwarn = "No current weather advisories"; $targettext[0] = "THERE ARE NO ACTIVE WATCHES, WARNINGS OR ADVISORIES"; }
if ($targetwarn <> "No current weather advisories") { Now.. no more funny characters in the output. Maybe it was PHP's subtle gripe about not being able to post 'Notice:' type messages. Sample: http://saratoga-weather.org/carterlake-warnings.phpFull script <?php
// Force Defaults for Zone and County if ( ! isset($_REQUEST['warnzone']) ) $_REQUEST['warnzone']="MIZ036"; if ( ! isset($_REQUEST['warncounty']) ) $_REQUEST['warncounty']="MIC069"; if ( ! isset($_REQUEST['warnlocal']) ) $_REQUEST['warnlocal']="East+Tawas";
//You can pass data to this script with: // http://www.tawasbayweather.com/scripts/warning.php?warnzone=MIZ036&warncounty=MIC069&warnlocal=East+Tawas //Where the zone is your zone and the county is your county and location is your location //using pluses in place of spaces
$warnzone = $_REQUEST['warnzone']; $warncounty = $_REQUEST['warncounty']; $warnlocal = $_REQUEST['warnlocal'];
//import NOAA Advisory info //data can be altered by changing the zone and county numbers //Target data ends up in $targetwarn and $targettext[0]
$html = implode('', file("http://www.crh.noaa.gov/showsigwx.php?warnzone=${warnzone}&warncounty=${warncounty}"));
//Get the advisory headers and put them in an array
preg_match_all('|<h3>(.*)</h3>|', $html, $headers); $warnheaders = $headers[1];
//Get the advisory text and put them into an array as well
preg_match_all('|<pre>(.*)</pre>|Uis', $html, $headers); $warntext = $headers[1];
//If there is more than one advisory, we need to set its priority
if (count($warnheaders) >= 1) {
$i = 0; $flag = 0;
//First, around here tornados are the biggest danger. A warning is critical information. //Display this one first no matter what!
while ($i < count($warnheaders)): if (preg_match("/Tornado Warning/i", $warnheaders[$i])) { $targetwarn = $warnheaders[$i]; $targettext = $warntext[$i]; $targettext = explode("$$",$targettext); $flag = 1; break; } $i++; endwhile;
//Next if there are none of the above found. Display the first warning message.
if ($flag == 0) { $i = 0; while ($i < count($warnheaders)): if (preg_match("/Warning/i", $warnheaders[$i])) { $targetwarn = $warnheaders[$i]; $targettext = $warntext[$i]; $targettext = explode("$$",$targettext); $flag = 1; break; } $i++; endwhile; }
//Next if there are none of the above found. Display the first watch message.
if ($flag == 0) { $i = 0; while ($i < count($warnheaders)): if (preg_match("/Watch/i", $warnheaders[$i])) { $targetwarn = $warnheaders[$i]; $targettext = $warntext[$i]; $targettext = explode("$$",$targettext); $flag = 1; break; } $i++; endwhile; }
//Next if there are none of the above found. Display the first advisory message.
if ($flag == 0) { $i = 0; while ($i < count($warnheaders)): if (preg_match("/Advisory/i", $warnheaders[$i])) { $targetwarn = $warnheaders[$i]; $targettext = $warntext[$i]; $targettext = explode("$$",$targettext); $flag = 1; break; } $i++; endwhile; }
//Next if there are none of the above found. Display the first statement message.
if ($flag == 0) { $i = 0; while ($i < count($warnheaders)): if (preg_match("/Statement/i", $warnheaders[$i])) { $targetwarn = $warnheaders[$i]; $targettext = $warntext[$i]; $targettext = explode("$$",$targettext); $flag = 1; break; } $i++; endwhile; }
//Next if there are none of the above found. Set the advisory to default message.
if (empty($targetwarn)) { $targetwarn = "No current weather advisories"; $targettext[0] = "THERE ARE NO ACTIVE WATCHES, WARNINGS OR ADVISORIES"; } else if ($targetwarn == "No Active Hazardous Weather Conditions Found") { $targetwarn = "No current weather advisories"; $targettext[0] = "THERE ARE NO ACTIVE WATCHES, WARNINGS OR ADVISORIES"; } else if ($targetwarn == "Hazardous Weather Outlook") { $targetwarn = "No current weather advisories"; $targettext[0] = "THERE ARE NO ACTIVE WATCHES, WARNINGS OR ADVISORIES"; } else if ($targetwarn == "Short Term Forecast") { $targetwarn = "No current weather advisories"; $targettext[0] = "THERE ARE NO ACTIVE WATCHES, WARNINGS OR ADVISORIES"; }
if ($targetwarn <> "No current weather advisories") {
$warnlist = 'ALL CURRENT ADVISORIES:';
for ($i = 0; $i <= count($warnheaders); $i++) { $warnheaderplus = preg_replace( '| |', '+', $warnheaders[$i] ); $warnlist = $warnlist . '<br><a href="http://www.crh.noaa.gov/showsigwx.php?warnzone=' . $warnzone. '&warncounty=' . $warncounty . '&local_place1=' . $warnlocal . '&product1=' . $warnheaderplus . '" target="_new">' . $warnheaders[$i] . '</a>'; } }
} echo "<b>"; echo $targetwarn; echo "</b>"; ?> Best regards, Ken
|
|
|
|
|
Logged
|
Ken True/Saratoga, CA, USA main site: saratoga-weather.orgDavis Vantage Pro Plus - FARS, Boltek-PCI/NexStorm, GRLevel3, WD, WL, VWS, Cumulus, Meteohub Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP
|
|
|
|
tbweather
|
 |
« Reply #17 on: February 15, 2007, 07:43:01 AM » |
|
Ken- You are a php genius. Script works like a charm- no more strange characters. It's odd that the original script seemed to work fine for months and then just decided to choke one day.
Thanks for your help on this.
|
|
|
|
|
Logged
|
|
|
|
sjmiller
Member
Offline
Posts: 2
|
 |
« Reply #18 on: April 28, 2007, 10:57:12 PM » |
|
Hi, I'm using the script as well. I get these errors: Notice: Undefined offset: 4 in C:\Sites\Single42\litohin\webroot\nwsforecast.php on line 143 Notice: Undefined offset: 4 in C:\Sites\Single42\litohin\webroot\nwsforecast.php on line 144 The link to the page where this code is running is: http://www.cwmro.com/nwsforecast.phpThanks Stefan
|
|
|
|
|
Logged
|
|
|
|
|
carterlake
|
 |
« Reply #19 on: April 29, 2007, 09:08:05 AM » |
|
Hi, I'm using the script as well. I get these errors: Notice: Undefined offset: 4 in C:\Sites\Single42\litohin\webroot\nwsforecast.php on line 143 Notice: Undefined offset: 4 in C:\Sites\Single42\litohin\webroot\nwsforecast.php on line 144 The link to the page where this code is running is: http://www.cwmro.com/nwsforecast.phpThanks Stefan So is Ken.... http://saratoga-weather.org/carterlake-warnings.php Ken?
|
|
|
|
|
Logged
|
  Davis VP2 6153; Weather Display (LIVE w/ Ajax); Quickcam for Notebooks Pro; Boltek w/ Nexstorm; GRLevel3; live NOAA Radio
|
|
|
sjmiller
Member
Offline
Posts: 2
|
 |
« Reply #20 on: April 29, 2007, 10:15:56 AM » |
|
I've fixed it. So you don't have to worry about which index it starts with or how many elements there are, you could use a foreach loop instead: foreach($warnheaders as $i => $value) { Instead of:for ($i = 0; $i <= count($warnheaders); $i++) {
|
|
|
|
|
Logged
|
|
|
|
spweather
Member
Offline
Posts: 18
Davis Wireless Vantage Pro Plus
|
 |
« Reply #21 on: July 08, 2007, 01:45:07 PM » |
|
I'm beginning to believe this bug is related to encoding. I got turned on to this script from Lew's www.tawasbayweather.com site. I copied the "fixed" version from this forum thread. With IE7 I had the extraneous characters that Lew had with Firefox. He sent me the script he was using and I had the same problems. Doing some testing I found the characters would appear with some warnings and not others (exp Severe Thunderstorms versus No Hazards). I noticed Lew's page used charset=us-ascii and at the time I had charset=windows-1252. I changed my encoding to charset=utf-8 (because that's what I decided to stick with) and the extraneous characters disappeared. Dennis www.sandpointweather.com
|
|
|
|
|
Logged
|
|
|
|
|