WXforum.net

Web Weather => Weather Website PHP/AJAX scripting => Topic started by: tmabell on February 19, 2021, 09:16:21 PM

Title: Old Anole AQI Script & PHP8
Post by: tmabell on February 19, 2021, 09:16:21 PM
I'm still using the old Larry Boyd (anole) AQI Air Quality Index script and while it threw a number of warnings in php 7.x, it did work.  I discovered however that under php 8 it no longer works at all.  Hopefully someone here might have an idea how to get it going again.  Here are the log entries from my server:

Warning: Undefined variable $urlActionDay in C:\www\wxaqirss.php on line 74
Fatal error: Uncaught ValueError: DOMDocument::load(): Argument #1 ($filename) must not be empty in C:\www\wxaqirss.php:243 Stack trace: #0 C:\www\wxaqirss.php(243): DOMDocument->load('') #1 C:\www\wxaqirss.php(74): getAQIdata(NULL, 'actionday') #2 {main} thrown in C:\www\wxaqirss.php on line 243


Obviously the fatal error is what's killing it.
Title: Re: Old Anole AQI Script & PHP8
Post by: the beteljuice on February 19, 2021, 10:26:21 PM
Try changing $urlActionDay in C:\www\wxaqirss.php on line 74 to

getAQIdata($urlActionday, "actionday");
Title: Re: Old Anole AQI Script & PHP8
Post by: tmabell on February 20, 2021, 08:01:08 AM
Unfortunately, that didn't work.  I may be missing something but that line appears exactly the same as the original?  Maybe I need more coffee  :???:
Title: Re: Old Anole AQI Script & PHP8
Post by: the beteljuice on February 20, 2021, 10:30:40 AM
Did you change it ????

Definitely was wrong ...

Line #34
$urlActionday = "https://feeds.enviroflash.info/rss/actionday/140.xml";  //South Bend, IN

Line #74
getAQIdata($urlActionDay, "actionday");

... and all the error messages are an escalation of the 'missing' url
Title: Re: Old Anole AQI Script & PHP8
Post by: tmabell on February 20, 2021, 10:50:20 AM
I had changed it but no change was noted so I changed line 74 to
Code: [Select]
getAQIdata($urlActionday, "actionday"); and now there is a change, but still not right:

https://mymishawakaweather.com/wxaqirss.php (https://mymishawakaweather.com/wxaqirss.php)

I'm attaching the edited copy.  I really appreciate the help!
Title: Re: Old Anole AQI Script & PHP8
Post by: saratogaWX on February 20, 2021, 11:45:47 AM
A couple more code glitches fixed in the attached.

Title: Re: Old Anole AQI Script & PHP8
Post by: tmabell on February 20, 2021, 12:18:38 PM
Thanks to The Beteljuice and to Ken for jumping in.  According to the server logs, there is one more issue on line 337 which is preventing the rest of the page from populating.

This is the logged error:

"[Sat Feb 20 12:17:09.784868 2021] [php:error] [pid 87692:tid 828] [client 192.168.10.1:55906] PHP Fatal error:  Uncaught Error: Undefined constant "imagesDir" in C:\\www\\wxaqirss.php:337\nStack trace:\n#0 C:\\www\\AQI.php(224): include()\n#1 {main}\n  thrown in C:\\www\\wxaqirss.php on line 337"


This is line 337: <td colspan="2" align="center"><img src="<?php print${imagesDir}?>aqi.gif" width="221" height="102" alt="" /><br /><br /></td>

Title: Re: Old Anole AQI Script & PHP8
Post by: the beteljuice on February 20, 2021, 12:32:03 PM
Cross posting ...

Just do the first one (line 334 now is 337)

O.K.

First of all ....

Code: [Select]
// line #334 (produces fatal error)
<td colspan="2" align="center"><img src="<?php print${imagesDir}?>aqi.gif" width="221" height="102" alt="" /><br /><br /></td>

// should be
<td colspan="2" align="center"><img src="<?php print $imagesDir?>aqi.gif" width="221" height="102" alt="" /><br /><br /></td>

#line #220
//$adtext = '';

// should be
$adtext = '';

// now we need to add a non-existant 'flag' ($real2)
// code block starting line #121
   // search for two AQI types
   if(preg_match('|<br /><br />\n(.*) - (.*) AQI - (.*)<br />(.*) - (.*) AQI - (.*)</div>|Uis', $realtime[0]["desc"])) {
      preg_match('|<br /><br />\n(.*) - (.*) AQI - (.*)<br />(.*) - (.*) AQI - (.*)</div>|Uis', $realtime[0]["desc"], $r3);
      $realIndex2 = trim(strip_tags($r3[4]));
      $realValue2 = trim(strip_tags($r3[5]));
      $realMeasure2 = trim(strip_tags($r3[6]));
   }

// needs to be
   // search for two AQI types
   $real2 = false;
   if(preg_match('|<br /><br />\n(.*) - (.*) AQI - (.*)<br />(.*) - (.*) AQI - (.*)</div>|Uis', $realtime[0]["desc"])) {
      preg_match('|<br /><br />\n(.*) - (.*) AQI - (.*)<br />(.*) - (.*) AQI - (.*)</div>|Uis', $realtime[0]["desc"], $r3);
      $realIndex2 = trim(strip_tags($r3[4]));
      $realValue2 = trim(strip_tags($r3[5]));
      $realMeasure2 = trim(strip_tags($r3[6]));
  $real2 = true;
   }

I think that will fix everything that's being complained about ...
... unless you tell me different

Title: Re: Old Anole AQI Script & PHP8
Post by: tmabell on February 20, 2021, 12:45:17 PM
That fixed everything!  Thank you for sticking with this and helping me along.  Your kindness and generosity are much appreciated.