WXforum.net
May 22, 2013, 07:59:39 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
Members: 6617  •  Posts: 178543  •  Topics: 18119
Please welcome TheMOX, our newest member.
Welcome to the the new hosting for WXforum.net.
 
   Home   Help Search Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: Extraneous characters added to weather warning  (Read 16586 times)
0 Members and 1 Guest are viewing this topic.
tbweather
Senior Member
**
Offline Offline

Posts: 99



WWW
« 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
Forecaster
*****
Offline Offline

Posts: 1651



« 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;


Code:

<td style="color:white; text-align:center">
<b>No current weather advisories</b>&nbsp;
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
Senior Contributor
****
Offline Offline

Posts: 243



WWW
« 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
Senior Member
**
Offline Offline

Posts: 99



WWW
« 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");
?>
&nbsp; 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
Forecaster
*****
Offline Offline

Posts: 1651



« Reply #4 on: February 14, 2007, 11:39:05 AM »

Code:
<?php 
include &#40;"http&#58;//www.tawasbayweather.com/scripts/warning.php"&#41;; 
?>



I do mine with an Include Virtual statement.


Code:

<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
Senior Contributor
****
Offline Offline

Posts: 243



WWW
« 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.php

What'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
tbweather
Senior Member
**
Offline Offline

Posts: 99



WWW
« Reply #6 on: February 14, 2007, 01:36:24 PM »

Thanks for all your help on this. I don't know much about php and have probably messed something up that just isn't apparent to me.

The script I am using is at http://www.tawasbayweather.com/scripts/warnings.php.txt
Logged

WeatherHost
Forecaster
*****
Offline Offline

Posts: 1651



« 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
Senior Member
**
Offline Offline

Posts: 99



WWW
« 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
Senior Member
**
Offline Offline

Posts: 99



WWW
« 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
Senior Contributor
****
Offline Offline

Posts: 243



WWW
« Reply #10 on: February 14, 2007, 03:59:15 PM »

If you're using PHP5, try replacing...

Code:
$html = implode('', file("http://www.crh.noaa.gov/showsigwx.php?warnzone=${warnzone}&warncounty=${warncounty}"));


with...

Code:
$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
Senior Member
**
Offline Offline

Posts: 99



WWW
« 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
Senior Contributor
****
Offline Offline

Posts: 243



WWW
« Reply #12 on: February 14, 2007, 06:16:22 PM »

That won't work then....

Try...

Code:
$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
Senior Member
**
Offline Offline

Posts: 99



WWW
« 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
Senior Contributor
****
Offline Offline

Posts: 243



WWW
« 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.php

No symbols.
Logged


Davis VP2 6153; Weather Display (LIVE w/ Ajax); Quickcam for Notebooks Pro; Boltek w/ Nexstorm; GRLevel3; live NOAA Radio
tbweather
Senior Member
**
Offline Offline

Posts: 99



WWW
« 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
Administrator
Forecaster
*****
Offline Offline

Posts: 3730


Saratoga, CA, USA Weather - free PHP scripts


WWW
« 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:
Code:
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
Code:
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.php

Full script
Code:
<?php

// Force Defaults for Zone and County
if &#40; ! isset&#40;$_REQUEST['warnzone'&#93;&#41; &#41;
        
$_REQUEST['warnzone'&#93;="MIZ036";
if &#40; ! isset&#40;$_REQUEST['warncounty'&#93;&#41; &#41;
        
$_REQUEST['warncounty'&#93;="MIC069";
if &#40; ! isset&#40;$_REQUEST['warnlocal'&#93;&#41; &#41;
        
$_REQUEST['warnlocal'&#93;="East+Tawas";

//You can pass data to this script with&#58;
// http&#58;//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'&#93;;
$warncounty $_REQUEST['warncounty'&#93;;
$warnlocal $_REQUEST['warnlocal'&#93;;

//import NOAA Advisory info
//data can be altered by changing the zone and county numbers
//Target data ends up in $targetwarn and $targettext[0&#93;

$html implode&#40;'', file&#40;"http&#58;//www.crh.noaa.gov/showsigwx.php?warnzone=$&#123;warnzone&#125;&warncounty=$&#123;warncounty&#125;"&#41;&#41;;

//Get the advisory headers and put them in an array

preg_match_all&#40;'|<h3>&#40;.*&#41;</h3>|', $html, $headers&#41;;
$warnheaders $headers[1&#93;;

//Get the advisory text and put them into an array as well

preg_match_all&#40;'|<pre>&#40;.*&#41;</pre>|Uis', $html, $headers&#41;;
$warntext $headers[1&#93;;

//If there is more than one advisory, we need to set its priority

if &#40;count&#40;$warnheaders&#41; >= 1&#41; &#123;

$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 &#40;$i < count&#40;$warnheaders&#41;&#41;&#58;
if &#40;preg_match&#40;"/Tornado Warning/i", $warnheaders[$i&#93;&#41;&#41; &#123;  
$targetwarn $warnheaders[$i&#93;;
$targettext $warntext[$i&#93;;
$targettext explode&#40;"$$",$targettext&#41;;
$flag 1;
break;
&#125;
$i++;
endwhile;

//Next if there are none of the above found. Display the first warning message.

if &#40;$flag == 0&#41; &#123;
$i 0;
while &#40;$i < count&#40;$warnheaders&#41;&#41;&#58;
if &#40;preg_match&#40;"/Warning/i", $warnheaders[$i&#93;&#41;&#41; &#123;  
$targetwarn $warnheaders[$i&#93;;
$targettext $warntext[$i&#93;;
$targettext explode&#40;"$$",$targettext&#41;;
$flag 1;
break;
&#125;
$i++;
endwhile;
&#125;

//Next if there are none of the above found. Display the first watch message.

if &#40;$flag == 0&#41; &#123;
$i 0;
while &#40;$i < count&#40;$warnheaders&#41;&#41;&#58;
if &#40;preg_match&#40;"/Watch/i", $warnheaders[$i&#93;&#41;&#41; &#123;  
$targetwarn $warnheaders[$i&#93;;
$targettext $warntext[$i&#93;;
$targettext explode&#40;"$$",$targettext&#41;;
$flag 1;
break;
&#125;
$i++;
endwhile;
&#125;

//Next if there are none of the above found. Display the first advisory message.

if &#40;$flag == 0&#41; &#123;
$i 0;
while &#40;$i < count&#40;$warnheaders&#41;&#41;&#58;
if &#40;preg_match&#40;"/Advisory/i", $warnheaders[$i&#93;&#41;&#41; &#123;  
$targetwarn $warnheaders[$i&#93;;
$targettext $warntext[$i&#93;;
$targettext explode&#40;"$$",$targettext&#41;;
$flag 1;
break;
&#125;
$i++;
endwhile;
&#125;

//Next if there are none of the above found. Display the first statement message.

if &#40;$flag == 0&#41; &#123;
$i 0;
while &#40;$i < count&#40;$warnheaders&#41;&#41;&#58;
if &#40;preg_match&#40;"/Statement/i", $warnheaders[$i&#93;&#41;&#41; &#123;  
$targetwarn $warnheaders[$i&#93;;
$targettext $warntext[$i&#93;;
$targettext explode&#40;"$$",$targettext&#41;;
$flag 1;
break;
&#125;
$i++;
endwhile;
&#125;

//Next if there are none of the above found. Set the advisory to default message.

if &#40;empty&#40;$targetwarn&#41;&#41; &#123;
$targetwarn "No current weather advisories";
$targettext[0&#93; = "THERE ARE NO ACTIVE WATCHES, WARNINGS OR ADVISORIES";
&#125; else if &#40;$targetwarn == "No Active Hazardous Weather Conditions Found"&#41; &#123;
$targetwarn "No current weather advisories";
$targettext[0&#93; = "THERE ARE NO ACTIVE WATCHES, WARNINGS OR ADVISORIES";
&#125; else if &#40;$targetwarn == "Hazardous Weather Outlook"&#41; &#123;
$targetwarn "No current weather advisories";
$targettext[0&#93; = "THERE ARE NO ACTIVE WATCHES, WARNINGS OR ADVISORIES";
&#125; else if &#40;$targetwarn == "Short Term Forecast"&#41; &#123;
$targetwarn "No current weather advisories";
$targettext[0&#93; = "THERE ARE NO ACTIVE WATCHES, WARNINGS OR ADVISORIES";
&#125;

if &#40;$targetwarn <> "No current weather advisories"&#41; &#123;

$warnlist 'ALL CURRENT ADVISORIES&#58;';

for &#40;$i = 0; $i <= count&#40;$warnheaders&#41;; $i++&#41; &#123;
     $warnheaderplus preg_replace&#40; '| |', '+', $warnheaders[$i&#93; &#41;;
     $warnlist $warnlist '<br><a href="http&#58;//www.crh.noaa.gov/showsigwx.php?warnzone=' $warnzone'&warncounty=' $warncounty '&local_place1=' $warnlocal '&product1=' $warnheaderplus '" target="_new">' $warnheaders[$i&#93; . '</a>';
&#125;
&#125;

&#125;
echo "<b>";
echo 
$targetwarn;
echo 
"</b>";
?>


Best regards,
Ken
Logged

Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis 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
Senior Member
**
Offline Offline

Posts: 99



WWW
« 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 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.php


Thanks
Stefan
Logged
carterlake
Senior Contributor
****
Offline Offline

Posts: 243



WWW
« Reply #19 on: April 29, 2007, 09:08:05 AM »

Quote from: "sjmiller"
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.php


Thanks
Stefan


So is Ken.... http://saratoga-weather.org/carterlake-warnings.php

 Wink

Ken?
Logged


Davis VP2 6153; Weather Display (LIVE w/ Ajax); Quickcam for Notebooks Pro; Boltek w/ Nexstorm; GRLevel3; live NOAA Radio
sjmiller
Member
*
Offline 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:

Code:
foreach($warnheaders as $i => $value) {


Instead of:

Code:
for ($i = 0; $i <= count($warnheaders); $i++) {
Logged
spweather
Member
*
Offline Offline

Posts: 18

Davis Wireless Vantage Pro Plus


WWW
« 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

Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.138 seconds with 19 queries.
anything