Solved

How in PHP can I read an XML file from weather.gov?

Posted on 2016-11-15
9
16 Views
Last Modified: 2016-11-21
This code works fine:
#!/usr/local/bin/php
<?php // demo/temp_it_architect.php
/**
 * https://www.experts-exchange.com/questions/28982054/PHP-code-to-retrieve-NDFD-weather-forecasts.html
 *
 * https://www.experts-exchange.com/articles/12239/Introduction-to-Application-Programming-Interfaces.html
 */
error_reporting(E_ALL);

$url = <<<EOD
http://graphical.weather.gov/xml/sample_products/browser_interface/ndfdBrowserClientByDay.php?whichClient=NDFDgenByDay&lat=42.8808333&lon=-85.5228056&listLatLon=&lat1=&lon1=&lat2=&lon2=&resolutionSub=&endPoint1Lat=&endPoint1Lon=&endPoint2Lat=&endPoint2Lon=&centerPointLat=&centerPointLon=&distanceLat=&distanceLon=&resolutionSquare=&zipCodeList=&citiesLevel=&format=24+hourly&startDate=&numDays=7&Unit=e&Submit=Submit
EOD;

// SHOW HOW TO RETRIEVE DATA FROM THE API
$xml = file_get_contents($url);
$obj = SimpleXML_Load_String($xml);
echo '<pre>';
var_dump($obj);

Open in new window

However, I ran into a snag.  I cannot get "wordedForecast" using REST from what I can see.  I can get it if I go here:
http://forecast.weather.gov/MapClick.php?lat=42.8808333&lon=-85.5228056&FcstType=dwml

Open in new window

The only problem is, I cannot get that to work with the above code.  How can I access the data from this link?

Thanks!
0
Comment
Question by:IT_Architect
  • 5
  • 4
9 Comments
 
LVL 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 500 total points
ID: 41888831
Looks like you may have to use cURL to read the file.  Don't understand why the government, supported by taxpayer dollars, would intentionally lock down access to public data, but it looks like they have done this.  Feh.

Please see: https://iconoun.com/demo/temp_it_architect_1.php
<?php // demo/temp_it_architect_1.php
/**
 * https://www.experts-exchange.com/questions/28983291/How-in-PHP-can-I-read-an-XML-file-from-weather-gov.html
 *
 * https://www.experts-exchange.com/articles/12239/Introduction-to-Application-Programming-Interfaces.html
 */
error_reporting(E_ALL);

$url = <<<EOD
http://forecast.weather.gov/MapClick.php?lat=42.8808333&lon=-85.5228056&FcstType=dwml
EOD;

// TRY THE REMOTE WEB SERVICE
$response = new GET_Response_Object($url);

// SHOW THE WORK PRODUCT
echo "<pre>";
if (!$response->document) var_dump($response);

// SHOW HOW TO RETRIEVE DATA FROM THE API
$obj = SimpleXML_Load_String($response->document);

// ACTIVATE THIS TO SEE THE ENTIRE OBJECT
// print_r($obj);

// EXTRACT INFORMATION FROM THE OBJECT
$loc = (string)$obj->data[0]->location->description;
$svt = (array)$obj->data[0]->{'time-layout'}[0]->{'start-valid-time'};
$wft = (array)$obj->data[0]->parameters->wordedForecast->text;

echo PHP_EOL . "Location: $loc";
echo PHP_EOL;

unset($svt["@attributes"]);
foreach ($svt as $key => $datetime)
{
    $fmt = date('M d, Y g:ia', strtotime($datetime));
    echo PHP_EOL . $fmt;
    echo PHP_EOL . $wft[$key];
    echo PHP_EOL;
}


Class GET_Response_Object
{
    public $href, $title, $http_code, $errno, $info, $document;

    public function __construct($href, $user=NULL, $pass=NULL, $get_array=[], $title=NULL)
    {
        // ACTIVATE THIS TO AVOID TIMEOUT FOR LONG RUNNING SCRIPT
        // set_time_limit(10);

        // STORE THE CALL INFORMATION
        $this->href  = $href;
        $this->title = $title;

        // PREPARE THE GET STRING
        $get_string = http_build_query($get_array);
        if ($get_string) $get_string = '?' . $get_string;

        // MAKE THE REQUEST
        if (!$response = $this->my_curl($href, $user, $pass, $get_string))
        {
            // ACTIVATE THIS TO SEE THE ERRORS AS THEY OCCUR
            trigger_error("Errno: $this->errno; HTTP: $this->http_code; URL: $this->href", E_USER_WARNING);
        }
        else
        {
            return $response;
        }
    }

    protected function my_curl($url, $user, $pass, $get_string, $timeout=3)
    {
        // PREPARE THE CURL CALL
        $curl = curl_init();

        // HEADERS AND OPTIONS APPEAR TO BE A FIREFOX BROWSER REFERRED BY GOOGLE
        $header[] = "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
        $header[] = "Cache-Control: max-age=0";
        $header[] = "Connection: keep-alive";
        $header[] = "Keep-Alive: 300";
        $header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
        $header[] = "Accept-Language: en-us,en;q=0.5";
        $header[] = "Pragma: "; // BROWSERS USUALLY LEAVE THIS BLANK

        // SET THE CURL OPTIONS - SEE http://php.net/manual/en/function.curl-setopt.php
        curl_setopt( $curl, CURLOPT_URL,            $url . $get_string  );
        curl_setopt( $curl, CURLOPT_USERAGENT,      'Mozilla/5.0 (Windows NT 6.1; rv:44.0) Gecko/20100101 Firefox/44.0'  );
        curl_setopt( $curl, CURLOPT_HTTPHEADER,     $header  );
        curl_setopt( $curl, CURLOPT_REFERER,        'http://www.google.com'  );
        curl_setopt( $curl, CURLOPT_ENCODING,       'gzip,deflate'  );
        curl_setopt( $curl, CURLOPT_AUTOREFERER,    TRUE  );
        curl_setopt( $curl, CURLOPT_RETURNTRANSFER, TRUE  );
        curl_setopt( $curl, CURLOPT_FOLLOWLOCATION, TRUE  );
        curl_setopt( $curl, CURLOPT_TIMEOUT,        $timeout  );
        curl_setopt( $curl, CURLOPT_HTTPAUTH,       CURLAUTH_ANY );
        curl_setopt( $curl, CURLOPT_USERPWD,        "$user:$pass" );

        curl_setopt( $curl, CURLOPT_VERBOSE,        TRUE   );
        curl_setopt( $curl, CURLOPT_FAILONERROR,    TRUE   );

        // SET THE LOCATION OF THE COOKIE JAR (THIS FILE WILL BE OVERWRITTEN)
        curl_setopt( $curl, CURLOPT_COOKIEFILE,     'cookie.txt' );
        curl_setopt( $curl, CURLOPT_COOKIEJAR,      'cookie.txt' );

        // IF USING SSL, THIS INFORMATION MAY BE IMPORTANT
        // http://php.net/manual/en/function.curl-setopt.php#110457
        // http://php.net/manual/en/function.curl-setopt.php#115993
        // http://php.net/manual/en/function.curl-setopt.php#113754
        // REDACTED IN 2015 curl_setopt( $curl, CURLOPT_SSLVERSION, 3 );
        curl_setopt( $curl, CURLOPT_SSL_VERIFYHOST, FALSE  );
        curl_setopt( $curl, CURLOPT_SSL_VERIFYPEER, FALSE  );

        // RUN THE CURL REQUEST AND GET THE RESULTS
        $this->document  = curl_exec($curl);
        $this->errno     = curl_errno($curl);
        $this->info      = curl_getinfo($curl);
        $this->http_code = $this->info['http_code'];
        curl_close($curl);

        return $this;
    }
}

Open in new window

0
 

Author Comment

by:IT_Architect
ID: 41888892
I get an error when I run it:
PHP Parse error:  syntax error, unexpected '[' in /home/test/test3.php on line 49

Open in new window

*The machine is on PHP 5.3
0
 

Accepted Solution

by:
IT_Architect earned 0 total points
ID: 41888935
I learned something:
NWS has implemented the requirement that all requests to forecast.weather.gov have a User-agent: header.
and
The new forecast-v3.weather.gov requires HTTPS only.
So... This works:
#!/usr/local/bin/php
<?php // demo/temp_it_architect.php
/**
 * https://www.experts-exchange.com/questions/28982054/PHP-code-to-retrieve-NDFD-weather-forecasts.html
 *
 * https://www.experts-exchange.com/articles/12239/Introduction-to-Application-Programming-Interfaces.html
 */
error_reporting(E_ALL);

$opts = array(
  'http'=>array(
  'method'=>"GET",
  'protocol_version' => 1.1,
  'header'=>"Cache-Control: no-cache, must-revalidate\r\n" .
            "Cache-control: max-age=0\r\n" .
            "Connection: close\r\n" .
            "User-agent: Forecast loader\r\n" .
            "Accept: text/plain,text/html\r\n"
  ),

  'https'=>array(
  'method'=>"GET",
  'protocol_version' => 1.1,
  'header'=>"Cache-Control: no-cache, must-revalidate\r\n" .
            "Cache-control: max-age=0\r\n" .
            "Connection: close\r\n" .
            "User-agent: Forecast loader\r\n" .
            "Accept: text/plain,text/html\r\n"
  )
);

$context = stream_context_create($opts);

// $url = <<<EOD
// http://graphical.weather.gov/xml/sample_products/browser_interface/ndfdBrowserClientByDay.php?whichClient=NDFDgenByDay&lat=42.8808333&lon=-85.5228056&listLatLon=&lat1=&lon1=&lat2=&lon2=&resolutionSub=&endPoint1Lat=&endPoint1Lon=&endPoint2Lat=&endPoint2Lon=&centerPointLat=&centerPointLon=&distanceLat=&distanceLon=&resolutionSquare=&zipCodeList=&citiesLevel=&format=24+hourly&startDate=&numDays=7&Unit=e&product=AFP&Submit=Submit
// EOD;
$url = <<<EOD
http://forecast.weather.gov/MapClick.php?lat=42.8808333&lon=-85.5228056&FcstType=dwml&Submit=Submit
EOD;

// SHOW HOW TO RETRIEVE DATA FROM THE API
// $xml = file_get_contents($url);
$xml = file_get_contents($url,false,$context);
$obj = SimpleXML_Load_String($xml);
echo '<pre>';
var_dump($obj);

Open in new window

Which outputs this, which has the added advantage of picking up the Forecast, 7-Day_Forecast, and the first Current in one hourly read.  For subsequent reads, I'll just download a new All_XML.zip every 15 minutes thereafter, which is comprised of individual files by ICAO for the in-between observations.  I may have a question or two on that as well.
<pre>object(SimpleXMLElement)#1 (3) {
  ["@attributes"]=>
  array(1) {
    ["version"]=>
    string(3) "1.0"
  }
  ["head"]=>
  object(SimpleXMLElement)#2 (2) {
    ["product"]=>
    object(SimpleXMLElement)#5 (3) {
      ["@attributes"]=>
      array(3) {
        ["concise-name"]=>
        string(9) "dwmlByDay"
        ["operational-mode"]=>
        string(13) "developmental"
        ["srsName"]=>
        string(8) "WGS 1984"
      }
      ["creation-date"]=>
      string(25) "2016-11-15T18:05:07-05:00"
      ["category"]=>
      string(33) "current observations and forecast"
    }
    ["source"]=>
    object(SimpleXMLElement)#6 (3) {
      ["production-center"]=>
      string(16) "Grand Rapids, MI"
      ["credit"]=>
      string(27) "http://www.weather.gov/grr/"
      ["more-information"]=>
      string(38) "http://www.nws.noaa.gov/forecasts/xml/"
    }
  }
  ["data"]=>
  array(2) {
    [0]=>
    object(SimpleXMLElement)#3 (5) {
      ["@attributes"]=>
      array(1) {
        ["type"]=>
        string(8) "forecast"
      }
      ["location"]=>
      object(SimpleXMLElement)#6 (5) {
        ["location-key"]=>
        string(6) "point1"
        ["description"]=>
        string(54) "Grand Rapids, Gerald R. Ford International Airport, MI"
        ["point"]=>
        object(SimpleXMLElement)#10 (1) {
          ["@attributes"]=>
          array(2) {
            ["latitude"]=>
            string(5) "42.89"
            ["longitude"]=>
            string(6) "-85.53"
          }
        }
        ["city"]=>
        string(50) "Grand Rapids, Gerald R. Ford International Airport"
        ["height"]=>
        string(3) "797"
      }
      ["moreWeatherInformation"]=>
      string(61) "http://forecast.weather.gov/MapClick.php?lat=42.89&lon=-85.53"
      ["time-layout"]=>
      array(3) {
        [0]=>
        object(SimpleXMLElement)#5 (3) {
          ["@attributes"]=>
          array(2) {
            ["time-coordinate"]=>
            string(5) "local"
            ["summarization"]=>
            string(8) "12hourly"
          }
          ["layout-key"]=>
          string(12) "k-p12h-n14-1"
          ["start-valid-time"]=>
          array(14) {
            [0]=>
            string(25) "2016-11-15T18:00:00-05:00"
            [1]=>
            string(25) "2016-11-16T06:00:00-05:00"
            [2]=>
            string(25) "2016-11-16T18:00:00-05:00"
            [3]=>
            string(25) "2016-11-17T06:00:00-05:00"
            [4]=>
            string(25) "2016-11-17T18:00:00-05:00"
            [5]=>
            string(25) "2016-11-18T06:00:00-05:00"
            [6]=>
            string(25) "2016-11-18T18:00:00-05:00"
            [7]=>
            string(25) "2016-11-19T06:00:00-05:00"
            [8]=>
            string(25) "2016-11-19T18:00:00-05:00"
            [9]=>
            string(25) "2016-11-20T06:00:00-05:00"
            [10]=>
            string(25) "2016-11-20T18:00:00-05:00"
            [11]=>
            string(25) "2016-11-21T06:00:00-05:00"
            [12]=>
            string(25) "2016-11-21T18:00:00-05:00"
            [13]=>
            string(25) "2016-11-22T06:00:00-05:00"
          }
        }
        [1]=>
        object(SimpleXMLElement)#7 (3) {
          ["@attributes"]=>
          array(2) {
            ["time-coordinate"]=>
            string(5) "local"
            ["summarization"]=>
            string(8) "12hourly"
          }
          ["layout-key"]=>
          string(11) "k-p24h-n7-1"
          ["start-valid-time"]=>
          array(7) {
            [0]=>
            string(25) "2016-11-15T18:00:00-05:00"
            [1]=>
            string(25) "2016-11-16T18:00:00-05:00"
            [2]=>
            string(25) "2016-11-17T18:00:00-05:00"
            [3]=>
            string(25) "2016-11-18T18:00:00-05:00"
            [4]=>
            string(25) "2016-11-19T18:00:00-05:00"
            [5]=>
            string(25) "2016-11-20T18:00:00-05:00"
            [6]=>
            string(25) "2016-11-21T18:00:00-05:00"
          }
        }
        [2]=>
        object(SimpleXMLElement)#8 (3) {
          ["@attributes"]=>
          array(2) {
            ["time-coordinate"]=>
            string(5) "local"
            ["summarization"]=>
            string(8) "12hourly"
          }
          ["layout-key"]=>
          string(11) "k-p24h-n7-2"
          ["start-valid-time"]=>
          array(7) {
            [0]=>
            string(25) "2016-11-16T06:00:00-05:00"
            [1]=>
            string(25) "2016-11-17T06:00:00-05:00"
            [2]=>
            string(25) "2016-11-18T06:00:00-05:00"
            [3]=>
            string(25) "2016-11-19T06:00:00-05:00"
            [4]=>
            string(25) "2016-11-20T06:00:00-05:00"
            [5]=>
            string(25) "2016-11-21T06:00:00-05:00"
            [6]=>
            string(25) "2016-11-22T06:00:00-05:00"
          }
        }
      }
      ["parameters"]=>
      object(SimpleXMLElement)#9 (7) {
        ["@attributes"]=>
        array(1) {
          ["applicable-location"]=>
          string(6) "point1"
        }
        ["temperature"]=>
        array(2) {
          [0]=>
          object(SimpleXMLElement)#10 (3) {
            ["@attributes"]=>
            array(3) {
              ["type"]=>
              string(7) "minimum"
              ["units"]=>
              string(10) "Fahrenheit"
              ["time-layout"]=>
              string(11) "k-p24h-n7-1"
            }
            ["name"]=>
            string(25) "Daily Minimum Temperature"
            ["value"]=>
            array(7) {
              [0]=>
              string(2) "43"
              [1]=>
              string(2) "41"
              [2]=>
              string(2) "53"
              [3]=>
              string(2) "39"
              [4]=>
              string(2) "30"
              [5]=>
              string(2) "27"
              [6]=>
              string(2) "27"
            }
          }
          [1]=>
          object(SimpleXMLElement)#11 (3) {
            ["@attributes"]=>
            array(3) {
              ["type"]=>
              string(7) "maximum"
              ["units"]=>
              string(10) "Fahrenheit"
              ["time-layout"]=>
              string(11) "k-p24h-n7-2"
            }
            ["name"]=>
            string(25) "Daily Maximum Temperature"
            ["value"]=>
            array(7) {
              [0]=>
              string(2) "57"
              [1]=>
              string(2) "68"
              [2]=>
              string(2) "68"
              [3]=>
              string(2) "42"
              [4]=>
              string(2) "38"
              [5]=>
              string(2) "41"
              [6]=>
              string(2) "44"
            }
          }
        }
        ["probability-of-precipitation"]=>
        object(SimpleXMLElement)#12 (3) {
          ["@attributes"]=>
          array(3) {
            ["type"]=>
            string(7) "12 hour"
            ["units"]=>
            string(7) "percent"
            ["time-layout"]=>
            string(12) "k-p12h-n14-1"
          }
          ["name"]=>
          string(38) "12 Hourly Probability of Precipitation"
          ["value"]=>
          array(14) {
            [0]=>
            string(2) "20"
            [1]=>
            object(SimpleXMLElement)#17 (0) {
            }
            [2]=>
            object(SimpleXMLElement)#18 (0) {
            }
            [3]=>
            object(SimpleXMLElement)#19 (0) {
            }
            [4]=>
            object(SimpleXMLElement)#20 (0) {
            }
            [5]=>
            string(2) "30"
            [6]=>
            string(2) "40"
            [7]=>
            object(SimpleXMLElement)#21 (0) {
            }
            [8]=>
            object(SimpleXMLElement)#22 (0) {
            }
            [9]=>
            object(SimpleXMLElement)#23 (0) {
            }
            [10]=>
            object(SimpleXMLElement)#24 (0) {
            }
            [11]=>
            object(SimpleXMLElement)#25 (0) {
            }
            [12]=>
            object(SimpleXMLElement)#26 (0) {
            }
            [13]=>
            object(SimpleXMLElement)#27 (0) {
            }
          }
        }
        ["weather"]=>
        object(SimpleXMLElement)#13 (3) {
          ["@attributes"]=>
          array(1) {
            ["time-layout"]=>
            string(12) "k-p12h-n14-1"
          }
          ["name"]=>
          string(33) "Weather Type, Coverage, Intensity"
          ["weather-conditions"]=>
          array(14) {
            [0]=>
            object(SimpleXMLElement)#27 (1) {
              ["@attributes"]=>
              array(1) {
                ["weather-summary"]=>
                string(35) "Slight Chance Showers and Areas Fog"
              }
            }
            [1]=>
            object(SimpleXMLElement)#26 (1) {
              ["@attributes"]=>
              array(1) {
                ["weather-summary"]=>
                string(27) "Areas Fog then Mostly Sunny"
              }
            }
            [2]=>
            object(SimpleXMLElement)#25 (1) {
              ["@attributes"]=>
              array(1) {
                ["weather-summary"]=>
                string(13) "Partly Cloudy"
              }
            }
            [3]=>
            object(SimpleXMLElement)#24 (1) {
              ["@attributes"]=>
              array(1) {
                ["weather-summary"]=>
                string(12) "Mostly Sunny"
              }
            }
            [4]=>
            object(SimpleXMLElement)#23 (1) {
              ["@attributes"]=>
              array(1) {
                ["weather-summary"]=>
                string(12) "Mostly Clear"
              }
            }
            [5]=>
            object(SimpleXMLElement)#22 (1) {
              ["@attributes"]=>
              array(1) {
                ["weather-summary"]=>
                string(32) "Mostly Sunny then Chance Showers"
              }
            }
            [6]=>
            object(SimpleXMLElement)#21 (1) {
              ["@attributes"]=>
              array(1) {
                ["weather-summary"]=>
                string(14) "Chance Showers"
              }
            }
            [7]=>
            object(SimpleXMLElement)#20 (1) {
              ["@attributes"]=>
              array(1) {
                ["weather-summary"]=>
                string(36) "Showers Likely then Rain/Snow Likely"
              }
            }
            [8]=>
            object(SimpleXMLElement)#19 (1) {
              ["@attributes"]=>
              array(1) {
                ["weather-summary"]=>
                string(48) "Rain/Snow Likely then Slight Chance Snow Showers"
              }
            }
            [9]=>
            object(SimpleXMLElement)#18 (1) {
              ["@attributes"]=>
              array(1) {
                ["weather-summary"]=>
                string(50) "Slight Chance Rain/Snow then Slight Chance Showers"
              }
            }
            [10]=>
            object(SimpleXMLElement)#17 (1) {
              ["@attributes"]=>
              array(1) {
                ["weather-summary"]=>
                string(13) "Mostly Cloudy"
              }
            }
            [11]=>
            object(SimpleXMLElement)#28 (1) {
              ["@attributes"]=>
              array(1) {
                ["weather-summary"]=>
                string(12) "Partly Sunny"
              }
            }
            [12]=>
            object(SimpleXMLElement)#29 (1) {
              ["@attributes"]=>
              array(1) {
                ["weather-summary"]=>
                string(13) "Mostly Cloudy"
              }
            }
            [13]=>
            object(SimpleXMLElement)#30 (1) {
              ["@attributes"]=>
              array(1) {
                ["weather-summary"]=>
                string(39) "Partly Sunny then Slight Chance Showers"
              }
            }
          }
        }
        ["conditions-icon"]=>
        object(SimpleXMLElement)#14 (3) {
          ["@attributes"]=>
          array(2) {
            ["type"]=>
            string(12) "forecast-NWS"
            ["time-layout"]=>
            string(12) "k-p12h-n14-1"
          }
          ["name"]=>
          string(15) "Conditions Icon"
          ["icon-link"]=>
          array(14) {
            [0]=>
            string(56) "http://forecast.weather.gov/newimages/medium/nshra20.png"
            [1]=>
            string(52) "http://forecast.weather.gov/DualImage.php?i=fg&j=sct"
            [2]=>
            string(53) "http://forecast.weather.gov/newimages/medium/nsct.png"
            [3]=>
            string(52) "http://forecast.weather.gov/newimages/medium/sct.png"
            [4]=>
            string(53) "http://forecast.weather.gov/newimages/medium/nfew.png"
            [5]=>
            string(60) "http://forecast.weather.gov/DualImage.php?i=sct&j=shra&jp=30"
            [6]=>
            string(56) "http://forecast.weather.gov/newimages/medium/nshra40.png"
            [7]=>
            string(66) "http://forecast.weather.gov/DualImage.php?i=shra&j=ra_sn&ip=0&jp=0"
            [8]=>
            string(66) "http://forecast.weather.gov/DualImage.php?i=nra_sn&j=nsn&ip=0&jp=0"
            [9]=>
            string(66) "http://forecast.weather.gov/DualImage.php?i=ra_sn&j=shra&ip=0&jp=0"
            [10]=>
            string(53) "http://forecast.weather.gov/newimages/medium/nbkn.png"
            [11]=>
            string(52) "http://forecast.weather.gov/newimages/medium/bkn.png"
            [12]=>
            string(53) "http://forecast.weather.gov/newimages/medium/nbkn.png"
            [13]=>
            string(59) "http://forecast.weather.gov/DualImage.php?i=bkn&j=shra&jp=0"
          }
        }
        ["hazards"]=>
        object(SimpleXMLElement)#15 (3) {
          ["@attributes"]=>
          array(1) {
            ["time-layout"]=>
            string(0) ""
          }
          ["name"]=>
          string(33) "Watches, Warnings, and Advisories"
          ["hazard-conditions"]=>
          object(SimpleXMLElement)#30 (1) {
            ["hazard"]=>
            object(SimpleXMLElement)#29 (2) {
              ["@attributes"]=>
              array(1) {
                ["headline"]=>
                string(25) "Hazardous Weather Outlook"
              }
              ["hazardTextURL"]=>
              string(197) "http://forecast.weather.gov/showsigwx.php?warnzone=MIZ057&warncounty=MIC081&firewxzone=MIZ057&local_place1=Grand+Rapids%2C+Gerald+R.+Ford+International+Airport+MI&product1=Hazardous+Weather+Outlook"
            }
          }
        }
        ["wordedForecast"]=>
        object(SimpleXMLElement)#16 (3) {
          ["@attributes"]=>
          array(3) {
            ["time-layout"]=>
            string(12) "k-p12h-n14-1"
            ["dataSource"]=>
            string(9) "grrNetcdf"
            ["wordGenerator"]=>
            string(12) "markMitchell"
          }
          ["name"]=>
          string(13) "Text Forecast"
          ["text"]=>
          array(14) {
            [0]=>
            string(216) "A slight chance of showers between 10pm and 1am.  Patchy fog before 11pm, then areas of fog after 4am.  Otherwise, mostly cloudy, with a low around 43. West southwest wind 3 to 6 mph.  Chance of precipitation is 20%."
            [1]=>
            string(99) "Areas of fog before 9am.  Otherwise, partly sunny, with a high near 57. Northwest wind 3 to 6 mph. "
            [2]=>
            string(101) "Partly cloudy, with a low around 41. Calm wind becoming south southeast around 6 mph after midnight. "
            [3]=>
            string(59) "Mostly sunny, with a high near 68. South wind 8 to 11 mph. "
            [4]=>
            string(62) "Mostly clear, with a low around 53. South wind around 10 mph. "
            [5]=>
            string(77) "A 30 percent chance of showers after 1pm.  Partly sunny, with a high near 68."
            [6]=>
            string(69) "A 40 percent chance of showers.  Mostly cloudy, with a low around 39."
            [7]=>
            string(96) "Rain showers likely before 5pm, then rain and snow showers likely.  Cloudy, with a high near 42."
            [8]=>
            string(133) "Snow showers likely, possibly mixed with rain before 8pm, then a slight chance of snow showers.  Mostly cloudy, with a low around 30."
            [9]=>
            string(149) "A slight chance of rain and snow showers before noon, then a slight chance of rain showers between noon and 1pm.  Mostly cloudy, with a high near 38."
            [10]=>
            string(36) "Mostly cloudy, with a low around 27."
            [11]=>
            string(34) "Partly sunny, with a high near 41."
            [12]=>
            string(36) "Mostly cloudy, with a low around 27."
            [13]=>
            string(63) "A slight chance of showers.  Partly sunny, with a high near 44."
          }
        }
      }
    }
    [1]=>
    object(SimpleXMLElement)#4 (5) {
      ["@attributes"]=>
      array(1) {
        ["type"]=>
        string(20) "current observations"
      }
      ["location"]=>
      object(SimpleXMLElement)#9 (4) {
        ["location-key"]=>
        string(6) "point1"
        ["point"]=>
        object(SimpleXMLElement)#5 (1) {
          ["@attributes"]=>
          array(2) {
            ["latitude"]=>
            string(5) "42.88"
            ["longitude"]=>
            string(6) "-85.52"
          }
        }
        ["area-description"]=>
        string(54) "Grand Rapids, Gerald R. Ford International Airport, MI"
        ["height"]=>
        string(3) "794"
      }
      ["moreWeatherInformation"]=>
      string(48) "http://www.nws.noaa.gov/data/obhistory/KGRR.html"
      ["time-layout"]=>
      object(SimpleXMLElement)#8 (3) {
        ["@attributes"]=>
        array(1) {
          ["time-coordinate"]=>
          string(5) "local"
        }
        ["layout-key"]=>
        string(10) "k-p1h-n1-1"
        ["start-valid-time"]=>
        string(25) "2016-11-15T17:53:00-05:00"
      }
      ["parameters"]=>
      object(SimpleXMLElement)#7 (8) {
        ["@attributes"]=>
        array(1) {
          ["applicable-location"]=>
          string(6) "point1"
        }
        ["temperature"]=>
        array(2) {
          [0]=>
          object(SimpleXMLElement)#5 (2) {
            ["@attributes"]=>
            array(3) {
              ["type"]=>
              string(8) "apparent"
              ["units"]=>
              string(10) "Fahrenheit"
              ["time-layout"]=>
              string(10) "k-p1h-n1-1"
            }
            ["value"]=>
            string(2) "48"
          }
          [1]=>
          object(SimpleXMLElement)#6 (2) {
            ["@attributes"]=>
            array(3) {
              ["type"]=>
              string(9) "dew point"
              ["units"]=>
              string(10) "Fahrenheit"
              ["time-layout"]=>
              string(10) "k-p1h-n1-1"
            }
            ["value"]=>
            string(2) "43"
          }
        }
        ["humidity"]=>
        object(SimpleXMLElement)#16 (2) {
          ["@attributes"]=>
          array(2) {
            ["type"]=>
            string(8) "relative"
            ["time-layout"]=>
            string(10) "k-p1h-n1-1"
          }
          ["value"]=>
          string(2) "83"
        }
        ["weather"]=>
        object(SimpleXMLElement)#15 (3) {
          ["@attributes"]=>
          array(1) {
            ["time-layout"]=>
            string(10) "k-p1h-n1-1"
          }
          ["name"]=>
          string(33) "Weather Type, Coverage, Intensity"
          ["weather-conditions"]=>
          array(2) {
            [0]=>
            object(SimpleXMLElement)#30 (1) {
              ["@attributes"]=>
              array(1) {
                ["weather-summary"]=>
                string(18) "Overcast with Haze"
              }
            }
            [1]=>
            object(SimpleXMLElement)#29 (1) {
              ["value"]=>
              object(SimpleXMLElement)#28 (1) {
                ["visibility"]=>
                string(4) "2.50"
              }
            }
          }
        }
        ["conditions-icon"]=>
        object(SimpleXMLElement)#14 (3) {
          ["@attributes"]=>
          array(2) {
            ["type"]=>
            string(12) "forecast-NWS"
            ["time-layout"]=>
            string(10) "k-p1h-n1-1"
          }
          ["name"]=>
          string(15) "Conditions Icon"
          ["icon-link"]=>
          string(53) "http://forecast.weather.gov/newimages/medium/novc.png"
        }
        ["direction"]=>
        object(SimpleXMLElement)#13 (2) {
          ["@attributes"]=>
          array(3) {
            ["type"]=>
            string(4) "wind"
            ["units"]=>
            string(12) "degrees true"
            ["time-layout"]=>
            string(10) "k-p1h-n1-1"
          }
          ["value"]=>
          string(3) "260"
        }
        ["wind-speed"]=>
        array(2) {
          [0]=>
          object(SimpleXMLElement)#12 (2) {
            ["@attributes"]=>
            array(3) {
              ["type"]=>
              string(4) "gust"
              ["units"]=>
              string(5) "knots"
              ["time-layout"]=>
              string(10) "k-p1h-n1-1"
            }
            ["value"]=>
            string(2) "NA"
          }
          [1]=>
          object(SimpleXMLElement)#11 (2) {
            ["@attributes"]=>
            array(3) {
              ["type"]=>
              string(9) "sustained"
              ["units"]=>
              string(5) "knots"
              ["time-layout"]=>
              string(10) "k-p1h-n1-1"
            }
            ["value"]=>
            string(1) "5"
          }
        }
        ["pressure"]=>
        object(SimpleXMLElement)#10 (2) {
          ["@attributes"]=>
          array(3) {
            ["type"]=>
            string(9) "barometer"
            ["units"]=>
            string(17) "inches of mercury"
            ["time-layout"]=>
            string(10) "k-p1h-n1-1"
          }
          ["value"]=>
          string(5) "29.86"
        }
      }
    }
  }
}

Open in new window


I've learned a TON from you.  THANKS TONS!!!
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 41888939
*The machine is on PHP 5.3
This PHP 5.3 installation is years out-of-date.  Please upgrade to one of the currently supported PHP versions!

You can download a current version by following one of the current version links in the upper right corner...
http://php.net/
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Comment

by:IT_Architect
ID: 41888946
This PHP 5.3 installation is years out-of-date.
That's true, and that is because there is software on it that won't run on newer.  :(
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 41889545
Better upgrade that old software!  Srsly, technology is always advancing and there is rarely any real advantage to clinging to old versions.

In PHP there are two ways to define an array.  Actually there are three, but these are the two you need to consider in the instant case.

Old:
$arr = array( 2,4,6 );

Open in new window

New:
$arr = [ 2,4,6 ];

Open in new window

In addition to making a slightly more efficient code set (because there is no need for a function call) the new way provides an array definition syntax that is more like JavaScript and JSON.   In other words, it helps make PHP look more like other familiar programming languages.

I'd be interested to know what software is locked into PHP 5.3, and why it's locked in!
0
 
LVL 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 500 total points
ID: 41889550
Sidebar note: The user-agent header in cURL is provided by this line, which deliberately appears to be a Firefox browser.

curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; rv:44.0) Gecko/20100101 Firefox/44.0');
0
 

Author Comment

by:IT_Architect
ID: 41889594
The VM is frozen at FreeBSD 7.2 and PHP 5.3 because one of the apps is encrypted, incompatible code, and the vendor long gone.  Back in 2008 we shut down our last OS-on-bare-metal server, and run unsupported (except for hardware) at Softlayer/IBM, where we install and maintain ESXi/vSphere, so creating a new VM with the latest software is not the problem.

Sidebar note:
Thanks again.
0
 

Author Closing Comment

by:IT_Architect
ID: 41895654
Works with less code
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now