Solved

XML Data Missing in PHP SimpleXML

Posted on 2016-11-22
8
19 Views
Last Modified: 2016-11-23
Interesting problem!  

When I show the XML on screen from:
http://forecast.weather.gov/MapClick.php?lat=43.03&lon=-85.55&FcstType=dwml&Submit=Submit
It displays:
<start-valid-time period-name="[b]Tonight[/b]">2016-11-22T19:00:00-05:00</start-valid-time>
In SimpleXML, it only shows:
           'start-valid-time' => 
          array (
            0 => '2016-11-22T19:00:00-05:00',

Open in new window

The period-name is missing.  How can I get it?

Thanks!
0
Comment
Question by:IT_Architect
  • 5
  • 3
8 Comments
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
period-name is not a data field -- it's an attribute of the tag.  You can use the @attributes() method to tease it out.

Also, if you ever find yourself in the position of producing XML for public consumption, please do two things...
(1) do not produce attributes
(2) do not produce XML -- make it JSON instead!
0
 

Author Comment

by:IT_Architect
Comment Utility
You can use the @attributes() method to tease it out.
It's not even included in the SimpleXML object.
This is the call for the XML:
$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);

$api_url = "http://forecast.weather.gov/MapClick.php";
$api_url_params = "?lat=42.8808333&lon=-85.5228056"; // Example
$api_url_suffix = "&FcstType=dwml&Submit=Submit";
$url = $api_url . $api_url_params . $api_url_suffix;
echo PHP_EOL . "***** url = " . $url;	echo PHP_EOL;	// debug

$xml = file_get_contents($url,false,$context);
echo PHP_EOL . "***** Export XML file" . PHP_EOL;
var_export($xml);	echo PHP_EOL;  // debug Send output to file using >

$obj = SimpleXML_Load_String($xml);
echo PHP_EOL . "***** Export obj = " . PHP_EOL;	// debug
var_export($obj);	// debug Send output to file using >
echo PHP_EOL;

Open in new window


This is the output of the URL passed.
***** url = http://forecast.weather.gov/MapClick.php?lat=43.03&lon=-85.55&FcstType=dwml&Submit=Submit

Open in new window


This is the XML file returned.  The attributes are present in the XML
'<?xml version="1.0" encoding="ISO-8859-1"?>
<dwml version="1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://graphical.weather.gov/xml/DWMLgen/schema/DWML.xsd">
  <head>
    <product concise-name="dwmlByDay" operational-mode="developmental" srsName="WGS 1984">
      <creation-date refresh-frequency=\'PT1H\'>2016-11-22T21:04:18-05:00</creation-date>
     <category>current observations and forecast</category>
    </product>
    <source>
      <production-center>Grand Rapids, MI</production-center>
      <credit>http://www.weather.gov/grr/</credit>
      <more-information>http://www.nws.noaa.gov/forecasts/xml/</more-information>
    </source>
  </head>
  <data type="forecast">

  <location>
    <location-key>point1</location-key>
    <point latitude="43.02" longitude="-85.54"/>
    <area-description>3 Miles ESE Northview MI</area-description>
    <height datum="mean sea level" height-units="feet">659</height>
  </location>
<moreWeatherInformation applicable-location="point1">http://forecast.weather.gov/MapClick.php?lat=43.02&amp;lon=-85.54</moreWeatherInformation>
  <time-layout time-coordinate="local" summarization="12hourly">
    <layout-key>k-p12h-n14-1</layout-key>
      <start-valid-time period-name="Tonight">2016-11-22T21:00:00-05:00</start-valid-time>
      <start-valid-time period-name="Wednesday">2016-11-23T06:00:00-05:00</start-valid-time>
      <start-valid-time period-name="Wednesday Night">2016-11-23T18:00:00-05:00</start-valid-time>
      <start-valid-time period-name="Thanksgiving Day">2016-11-24T06:00:00-05:00</start-valid-time>
      <start-valid-time period-name="Thursday Night">2016-11-24T18:00:00-05:00</start-valid-time>
      <start-valid-time period-name="Friday">2016-11-25T06:00:00-05:00</start-valid-time>
      <start-valid-time period-name="Friday Night">2016-11-25T18:00:00-05:00</start-valid-time>
      <start-valid-time period-name="Saturday">2016-11-26T06:00:00-05:00</start-valid-time>
      <start-valid-time period-name="Saturday Night">2016-11-26T18:00:00-05:00</start-valid-time>
      <start-valid-time period-name="Sunday">2016-11-27T06:00:00-05:00</start-valid-time>
      <start-valid-time period-name="Sunday Night">2016-11-27T18:00:00-05:00</start-valid-time>
      <start-valid-time period-name="Monday">2016-11-28T06:00:00-05:00</start-valid-time>
      <start-valid-time period-name="Monday Night">2016-11-28T18:00:00-05:00</start-valid-time>
      <start-valid-time period-name="Tuesday">2016-11-29T06:00:00-05:00</start-valid-time>
  </time-layout>

  <time-layout time-coordinate="local" summarization="12hourly">
    <layout-key>k-p24h-n7-1</layout-key>
      <start-valid-time period-name="Tonight">2016-11-22T21:00:00-05:00</start-valid-time>
      <start-valid-time period-name="Wednesday Night">2016-11-23T18:00:00-05:00</start-valid-time>
      <start-valid-time period-name="Thursday Night">2016-11-24T18:00:00-05:00</start-valid-time>
      <start-valid-time period-name="Friday Night">2016-11-25T18:00:00-05:00</start-valid-time>
      <start-valid-time period-name="Saturday Night">2016-11-26T18:00:00-05:00</start-valid-time>
      <start-valid-time period-name="Sunday Night">2016-11-27T18:00:00-05:00</start-valid-time>
      <start-valid-time period-name="Monday Night">2016-11-28T18:00:00-05:00</start-valid-time>
  </time-layout>

  <time-layout time-coordinate="local" summarization="12hourly">
    <layout-key>k-p24h-n7-2</layout-key>
      <start-valid-time period-name="Wednesday">2016-11-23T06:00:00-05:00</start-valid-time>
      <start-valid-time period-name="Thanksgiving Day">2016-11-24T06:00:00-05:00</start-valid-time>
      <start-valid-time period-name="Friday">2016-11-25T06:00:00-05:00</start-valid-time>
      <start-valid-time period-name="Saturday">2016-11-26T06:00:00-05:00</start-valid-time>
      <start-valid-time period-name="Sunday">2016-11-27T06:00:00-05:00</start-valid-time>
      <start-valid-time period-name="Monday">2016-11-28T06:00:00-05:00</start-valid-time>
      <start-valid-time period-name="Tuesday">2016-11-29T06:00:00-05:00</start-valid-time>
  </time-layout>


  <parameters applicable-location="point1">

    <temperature type="minimum" units="Fahrenheit" time-layout="k-p24h-n7-1">
      <name>Daily Minimum Temperature</name>
        <value>28</value>
        <value>35</value>
        <value>34</value>
        <value>33</value>
        <value>31</value>
        <value>38</value>
        <value>38</value>
    </temperature>

    <temperature type="maximum" units="Fahrenheit" time-layout="k-p24h-n7-2">
      <name>Daily Maximum Temperature</name>
        <value>38</value>
        <value>44</value>
        <value>41</value>
        <value>44</value>
        <value>46</value>
        <value>48</value>
        <value>43</value>
    </temperature>

    <probability-of-precipitation  type="12 hour" units="percent" time-layout="k-p12h-n14-1">
      <name>12 Hourly Probability of Precipitation</name>
        <value>30</value>
        <value>80</value>
        <value>70</value>
        <value xsi:nil="true"></value>
        <value>30</value>
        <value>40</value>
        <value>20</value>
        <value xsi:nil="true"></value>
        <value xsi:nil="true"></value>
        <value xsi:nil="true"></value>
        <value xsi:nil="true"></value>
        <value xsi:nil="true"></value>
        <value xsi:nil="true"></value>
        <value xsi:nil="true"></value>
    </probability-of-precipitation>

    <weather time-layout="k-p12h-n14-1">
      <name>Weather Type, Coverage, Intensity</name>
        <weather-conditions weather-summary="Mostly Cloudy then Chance Wintry Mix"/>
        <weather-conditions weather-summary="Wintry Mix"/>
        <weather-conditions weather-summary="Rain Likely"/>
        <weather-conditions weather-summary="Cloudy"/>
        <weather-conditions weather-summary="Slight Chance Rain then Chance Rain/Snow"/>
        <weather-conditions weather-summary="Chance Showers"/>
        <weather-conditions weather-summary="Slight Chance Snow Showers"/>
        <weather-conditions weather-summary="Partly Sunny"/>
        <weather-conditions weather-summary="Partly Cloudy"/>
        <weather-conditions weather-summary="Partly Sunny"/>
        <weather-conditions weather-summary="Showers Likely"/>
        <weather-conditions weather-summary="Chance Showers"/>
        <weather-conditions weather-summary="Chance Showers then Rain/Snow Likely"/>
        <weather-conditions weather-summary="Chance Rain/Snow"/>
    </weather>

    <conditions-icon type="forecast-NWS" time-layout="k-p12h-n14-1">
      <name>Conditions Icon</name>        <icon-link>http://forecast.weather.gov/DualImage.php?i=nbkn&amp;j=nfzra_sn&amp;jp=30</icon-link>
        <icon-link>http://forecast.weather.gov/newimages/medium/fzra_sn80.png</icon-link>
        <icon-link>http://forecast.weather.gov/newimages/medium/nra70.png</icon-link>
        <icon-link>http://forecast.weather.gov/newimages/medium/ovc.png</icon-link>
        <icon-link>http://forecast.weather.gov/DualImage.php?i=nra&amp;j=nra_sn&amp;ip=20&amp;jp=30</icon-link>
        <icon-link>http://forecast.weather.gov/newimages/medium/shra40.png</icon-link>
        <icon-link>http://forecast.weather.gov/newimages/medium/nsn20.png</icon-link>
        <icon-link>http://forecast.weather.gov/newimages/medium/bkn.png</icon-link>
        <icon-link>http://forecast.weather.gov/newimages/medium/nsct.png</icon-link>
        <icon-link>http://forecast.weather.gov/newimages/medium/bkn.png</icon-link>
        <icon-link>http://forecast.weather.gov/newimages/medium/nshra.png</icon-link>
        <icon-link>http://forecast.weather.gov/newimages/medium/shra.png</icon-link>
        <icon-link>http://forecast.weather.gov/DualImage.php?i=nshra&amp;j=nra_sn&amp;ip=0&amp;jp=0</icon-link>
        <icon-link>http://forecast.weather.gov/newimages/medium/ra_sn.png</icon-link>
    </conditions-icon>

    <hazards time-layout="">
      <name>Watches, Warnings, and Advisories</name>
      <hazard-conditions>
        <hazard headline="Hazardous Weather Outlook">
          <hazardTextURL>http://forecast.weather.gov/showsigwx.php?warnzone=MIZ057&amp;warncounty=MIC081&amp;firewxzone=MIZ057&amp;local_place1=3+Miles+ESE+Northview+MI&amp;product1=Hazardous+Weather+Outlook</hazardTextURL>
        </hazard>
      </hazard-conditions>
    </hazards>

    <wordedForecast time-layout="k-p12h-n14-1" dataSource="grrNetcdf" wordGenerator="markMitchell">
      <name>Text Forecast</name>
        <text>A chance of snow and freezing rain, mainly after 3am.  Mostly cloudy, with a low around 28. East wind 7 to 9 mph.  Chance of precipitation is 30%.</text>
        <text>Rain likely, possibly mixed with snow and freezing rain before 7am, then rain and snow likely between 7am and 1pm, then rain after 1pm.  High near 38. East southeast wind 10 to 14 mph.  Chance of precipitation is 80%. Little or no ice accumulation expected.  Little or no snow accumulation expected. </text>
        <text>Rain likely, mainly before 1am.  Cloudy, with a low around 35. Southeast wind 5 to 10 mph becoming light  after midnight.  Chance of precipitation is 70%. New precipitation amounts between a tenth and quarter of an inch possible. </text>
        <text>Cloudy, with a high near 44. South southwest wind 5 to 7 mph becoming west in the afternoon. </text>
        <text>A slight chance of rain before 1am, then a chance of rain and snow.  Cloudy, with a low around 34. West wind around 6 mph.  Chance of precipitation is 30%.</text>
        <text>A 40 percent chance of showers.  Cloudy, with a high near 41.</text>
        <text>A 20 percent chance of snow showers before 1am.  Mostly cloudy, with a low around 33.</text>
        <text>Partly sunny, with a high near 44.</text>
        <text>Partly cloudy, with a low around 31.</text>
        <text>Partly sunny, with a high near 46.</text>
        <text>Showers likely.  Mostly cloudy, with a low around 38.</text>
        <text>A chance of showers.  Cloudy, with a high near 48.</text>
        <text>Rain and snow showers likely.  Mostly cloudy, with a low around 38.</text>
        <text>A chance of rain and snow showers.  Mostly cloudy, with a high near 43.</text>
    </wordedForecast>

</parameters>
</data>
<data type="current observations">
	<location>
		<location-key>point1</location-key>
		<point latitude="42.88" longitude="-85.52"/>
		<area-description>Grand Rapids, Gerald R. Ford International Airport, MI</area-description>
		<height datum="mean sea level" height-units="feet">794</height>
	</location>
	<moreWeatherInformation applicable-location="point1">http://www.nws.noaa.gov/data/obhistory/KGRR.html</moreWeatherInformation>	<time-layout time-coordinate="local">	<layout-key>k-p1h-n1-1</layout-key>	<start-valid-time period-name="current">2016-11-22T20:53:00-05:00</start-valid-time>	</time-layout>	<parameters applicable-location="point1">	<temperature type="apparent" units="Fahrenheit" time-layout="k-p1h-n1-1">	<value>29</value>	</temperature>	<temperature type="dew point" units="Fahrenheit" time-layout="k-p1h-n1-1">	<value>22</value>	</temperature>	<humidity type="relative" time-layout="k-p1h-n1-1">	<value>75</value>	</humidity>	<weather time-layout="k-p1h-n1-1">	<name>Weather Type, Coverage, Intensity</name>	<weather-conditions weather-summary="A Few Clouds"/>	<weather-conditions>	<value>	<visibility units="statute miles">10.00</visibility>	</value>	</weather-conditions>	</weather>	<conditions-icon type="forecast-NWS" time-layout="k-p1h-n1-1">	<name>Conditions Icon</name>	<icon-link>http://forecast.weather.gov/newimages/medium/nfew.png</icon-link>	</conditions-icon>	<direction type="wind" units="degrees true" time-layout="k-p1h-n1-1">	<value>90</value>	</direction>	<wind-speed type="gust" units="knots" time-layout="k-p1h-n1-1">	<value>NA</value>	</wind-speed>	<wind-speed type="sustained" units="knots" time-layout="k-p1h-n1-1">	<value>6</value>	</wind-speed>		<pressure type="barometer" units="inches of mercury" time-layout="k-p1h-n1-1">			<value>30.29</value>		</pressure>	</parameters></data></dwml>'

Open in new window


This is the object created from the XML.  The attributes are missing.
***** Export obj = 
SimpleXMLElement::__set_state(array(
   '@attributes' => 
  array (
    'version' => '1.0',
  ),
   'head' => 
  SimpleXMLElement::__set_state(array(
     'product' => 
    SimpleXMLElement::__set_state(array(
       '@attributes' => 
      array (
        'concise-name' => 'dwmlByDay',
        'operational-mode' => 'developmental',
        'srsName' => 'WGS 1984',
      ),
       'creation-date' => '2016-11-22T21:04:18-05:00',
       'category' => 'current observations and forecast',
    )),
     'source' => 
    SimpleXMLElement::__set_state(array(
       'production-center' => 'Grand Rapids, MI',
       'credit' => 'http://www.weather.gov/grr/',
       'more-information' => 'http://www.nws.noaa.gov/forecasts/xml/',
    )),
  )),
   'data' => 
  array (
    0 => 
    SimpleXMLElement::__set_state(array(
       '@attributes' => 
      array (
        'type' => 'forecast',
      ),
       'location' => 
      SimpleXMLElement::__set_state(array(
         'location-key' => 'point1',
         'point' => 
        SimpleXMLElement::__set_state(array(
           '@attributes' => 
          array (
            'latitude' => '43.02',
            'longitude' => '-85.54',
          ),
        )),
         'area-description' => '3 Miles ESE Northview MI',
         'height' => '659',
      )),
       'moreWeatherInformation' => 'http://forecast.weather.gov/MapClick.php?lat=43.02&lon=-85.54',
       'time-layout' => 
      array (
        0 => 
        SimpleXMLElement::__set_state(array(
           '@attributes' => 
          array (
            'time-coordinate' => 'local',
            'summarization' => '12hourly',
          ),
           'layout-key' => 'k-p12h-n14-1',
           'start-valid-time' => 
          array (
            0 => '2016-11-22T21:00:00-05:00',
            1 => '2016-11-23T06:00:00-05:00',
            2 => '2016-11-23T18:00:00-05:00',
            3 => '2016-11-24T06:00:00-05:00',
            4 => '2016-11-24T18:00:00-05:00',
            5 => '2016-11-25T06:00:00-05:00',
            6 => '2016-11-25T18:00:00-05:00',
            7 => '2016-11-26T06:00:00-05:00',
            8 => '2016-11-26T18:00:00-05:00',
            9 => '2016-11-27T06:00:00-05:00',
            10 => '2016-11-27T18:00:00-05:00',
            11 => '2016-11-28T06:00:00-05:00',
            12 => '2016-11-28T18:00:00-05:00',
            13 => '2016-11-29T06:00:00-05:00',
          ),
        )),
        1 => 
        SimpleXMLElement::__set_state(array(
           '@attributes' => 
          array (
            'time-coordinate' => 'local',
            'summarization' => '12hourly',
          ),
           'layout-key' => 'k-p24h-n7-1',
           'start-valid-time' => 
          array (
            0 => '2016-11-22T21:00:00-05:00',
            1 => '2016-11-23T18:00:00-05:00',
            2 => '2016-11-24T18:00:00-05:00',
            3 => '2016-11-25T18:00:00-05:00',
            4 => '2016-11-26T18:00:00-05:00',
            5 => '2016-11-27T18:00:00-05:00',
            6 => '2016-11-28T18:00:00-05:00',
          ),
        )),
        2 => 
        SimpleXMLElement::__set_state(array(
           '@attributes' => 
          array (
            'time-coordinate' => 'local',
            'summarization' => '12hourly',
          ),
           'layout-key' => 'k-p24h-n7-2',
           'start-valid-time' => 
          array (
            0 => '2016-11-23T06:00:00-05:00',
            1 => '2016-11-24T06:00:00-05:00',
            2 => '2016-11-25T06:00:00-05:00',
            3 => '2016-11-26T06:00:00-05:00',
            4 => '2016-11-27T06:00:00-05:00',
            5 => '2016-11-28T06:00:00-05:00',
            6 => '2016-11-29T06:00:00-05:00',
          ),
        )),
      ),
       'parameters' => 
      SimpleXMLElement::__set_state(array(
         '@attributes' => 
        array (
          'applicable-location' => 'point1',
        ),
         'temperature' => 
        array (
          0 => 
          SimpleXMLElement::__set_state(array(
             '@attributes' => 
            array (
              'type' => 'minimum',
              'units' => 'Fahrenheit',
              'time-layout' => 'k-p24h-n7-1',
            ),
             'name' => 'Daily Minimum Temperature',
             'value' => 
            array (
              0 => '28',
              1 => '35',
              2 => '34',
              3 => '33',
              4 => '31',
              5 => '38',
              6 => '38',
            ),
          )),
          1 => 
          SimpleXMLElement::__set_state(array(
             '@attributes' => 
            array (
              'type' => 'maximum',
              'units' => 'Fahrenheit',
              'time-layout' => 'k-p24h-n7-2',
            ),
             'name' => 'Daily Maximum Temperature',
             'value' => 
            array (
              0 => '38',
              1 => '44',
              2 => '41',
              3 => '44',
              4 => '46',
              5 => '48',
              6 => '43',
            ),
          )),
        ),
         'probability-of-precipitation' => 
        SimpleXMLElement::__set_state(array(
           '@attributes' => 
          array (
            'type' => '12 hour',
            'units' => 'percent',
            'time-layout' => 'k-p12h-n14-1',
          ),
           'name' => '12 Hourly Probability of Precipitation',
           'value' => 
          array (
            0 => '30',
            1 => '80',
            2 => '70',
            3 => 
            SimpleXMLElement::__set_state(array(
            )),
            4 => '30',
            5 => '40',
            6 => '20',
            7 => 
            SimpleXMLElement::__set_state(array(
            )),
            8 => 
            SimpleXMLElement::__set_state(array(
            )),
            9 => 
            SimpleXMLElement::__set_state(array(
            )),
            10 => 
            SimpleXMLElement::__set_state(array(
            )),
            11 => 
            SimpleXMLElement::__set_state(array(
            )),
            12 => 
            SimpleXMLElement::__set_state(array(
            )),
            13 => 
            SimpleXMLElement::__set_state(array(
            )),
          ),
        )),
         'weather' => 
        SimpleXMLElement::__set_state(array(
           '@attributes' => 
          array (
            'time-layout' => 'k-p12h-n14-1',
          ),
           'name' => 'Weather Type, Coverage, Intensity',
           'weather-conditions' => 
          array (
            0 => 
            SimpleXMLElement::__set_state(array(
               '@attributes' => 
              array (
                'weather-summary' => 'Mostly Cloudy then Chance Wintry Mix',
              ),
            )),
            1 => 
            SimpleXMLElement::__set_state(array(
               '@attributes' => 
              array (
                'weather-summary' => 'Wintry Mix',
              ),
            )),
            2 => 
            SimpleXMLElement::__set_state(array(
               '@attributes' => 
              array (
                'weather-summary' => 'Rain Likely',
              ),
            )),
            3 => 
            SimpleXMLElement::__set_state(array(
               '@attributes' => 
              array (
                'weather-summary' => 'Cloudy',
              ),
            )),
            4 => 
            SimpleXMLElement::__set_state(array(
               '@attributes' => 
              array (
                'weather-summary' => 'Slight Chance Rain then Chance Rain/Snow',
              ),
            )),
            5 => 
            SimpleXMLElement::__set_state(array(
               '@attributes' => 
              array (
                'weather-summary' => 'Chance Showers',
              ),
            )),
            6 => 
            SimpleXMLElement::__set_state(array(
               '@attributes' => 
              array (
                'weather-summary' => 'Slight Chance Snow Showers',
              ),
            )),
            7 => 
            SimpleXMLElement::__set_state(array(
               '@attributes' => 
              array (
                'weather-summary' => 'Partly Sunny',
              ),
            )),
            8 => 
            SimpleXMLElement::__set_state(array(
               '@attributes' => 
              array (
                'weather-summary' => 'Partly Cloudy',
              ),
            )),
            9 => 
            SimpleXMLElement::__set_state(array(
               '@attributes' => 
              array (
                'weather-summary' => 'Partly Sunny',
              ),
            )),
            10 => 
            SimpleXMLElement::__set_state(array(
               '@attributes' => 
              array (
                'weather-summary' => 'Showers Likely',
              ),
            )),
            11 => 
            SimpleXMLElement::__set_state(array(
               '@attributes' => 
              array (
                'weather-summary' => 'Chance Showers',
              ),
            )),
            12 => 
            SimpleXMLElement::__set_state(array(
               '@attributes' => 
              array (
                'weather-summary' => 'Chance Showers then Rain/Snow Likely',
              ),
            )),
            13 => 
            SimpleXMLElement::__set_state(array(
               '@attributes' => 
              array (
                'weather-summary' => 'Chance Rain/Snow',
              ),
            )),
          ),
        )),
         'conditions-icon' => 
        SimpleXMLElement::__set_state(array(
           '@attributes' => 
          array (
            'type' => 'forecast-NWS',
            'time-layout' => 'k-p12h-n14-1',
          ),
           'name' => 'Conditions Icon',
           'icon-link' => 
          array (
            0 => 'http://forecast.weather.gov/DualImage.php?i=nbkn&j=nfzra_sn&jp=30',
            1 => 'http://forecast.weather.gov/newimages/medium/fzra_sn80.png',
            2 => 'http://forecast.weather.gov/newimages/medium/nra70.png',
            3 => 'http://forecast.weather.gov/newimages/medium/ovc.png',
            4 => 'http://forecast.weather.gov/DualImage.php?i=nra&j=nra_sn&ip=20&jp=30',
            5 => 'http://forecast.weather.gov/newimages/medium/shra40.png',
            6 => 'http://forecast.weather.gov/newimages/medium/nsn20.png',
            7 => 'http://forecast.weather.gov/newimages/medium/bkn.png',
            8 => 'http://forecast.weather.gov/newimages/medium/nsct.png',
            9 => 'http://forecast.weather.gov/newimages/medium/bkn.png',
            10 => 'http://forecast.weather.gov/newimages/medium/nshra.png',
            11 => 'http://forecast.weather.gov/newimages/medium/shra.png',
            12 => 'http://forecast.weather.gov/DualImage.php?i=nshra&j=nra_sn&ip=0&jp=0',
            13 => 'http://forecast.weather.gov/newimages/medium/ra_sn.png',
          ),
        )),
         'hazards' => 
        SimpleXMLElement::__set_state(array(
           '@attributes' => 
          array (
            'time-layout' => '',
          ),
           'name' => 'Watches, Warnings, and Advisories',
           'hazard-conditions' => 
          SimpleXMLElement::__set_state(array(
             'hazard' => 
            SimpleXMLElement::__set_state(array(
               '@attributes' => 
              array (
                'headline' => 'Hazardous Weather Outlook',
              ),
               'hazardTextURL' => 'http://forecast.weather.gov/showsigwx.php?warnzone=MIZ057&warncounty=MIC081&firewxzone=MIZ057&local_place1=3+Miles+ESE+Northview+MI&product1=Hazardous+Weather+Outlook',
            )),
          )),
        )),
         'wordedForecast' => 
        SimpleXMLElement::__set_state(array(
           '@attributes' => 
          array (
            'time-layout' => 'k-p12h-n14-1',
            'dataSource' => 'grrNetcdf',
            'wordGenerator' => 'markMitchell',
          ),
           'name' => 'Text Forecast',
           'text' => 
          array (
            0 => 'A chance of snow and freezing rain, mainly after 3am.  Mostly cloudy, with a low around 28. East wind 7 to 9 mph.  Chance of precipitation is 30%.',
            1 => 'Rain likely, possibly mixed with snow and freezing rain before 7am, then rain and snow likely between 7am and 1pm, then rain after 1pm.  High near 38. East southeast wind 10 to 14 mph.  Chance of precipitation is 80%. Little or no ice accumulation expected.  Little or no snow accumulation expected. ',
            2 => 'Rain likely, mainly before 1am.  Cloudy, with a low around 35. Southeast wind 5 to 10 mph becoming light  after midnight.  Chance of precipitation is 70%. New precipitation amounts between a tenth and quarter of an inch possible. ',
            3 => 'Cloudy, with a high near 44. South southwest wind 5 to 7 mph becoming west in the afternoon. ',
            4 => 'A slight chance of rain before 1am, then a chance of rain and snow.  Cloudy, with a low around 34. West wind around 6 mph.  Chance of precipitation is 30%.',
            5 => 'A 40 percent chance of showers.  Cloudy, with a high near 41.',
            6 => 'A 20 percent chance of snow showers before 1am.  Mostly cloudy, with a low around 33.',
            7 => 'Partly sunny, with a high near 44.',
            8 => 'Partly cloudy, with a low around 31.',
            9 => 'Partly sunny, with a high near 46.',
            10 => 'Showers likely.  Mostly cloudy, with a low around 38.',
            11 => 'A chance of showers.  Cloudy, with a high near 48.',
            12 => 'Rain and snow showers likely.  Mostly cloudy, with a low around 38.',
            13 => 'A chance of rain and snow showers.  Mostly cloudy, with a high near 43.',
          ),
        )),
      )),
    )),
    1 => 
    SimpleXMLElement::__set_state(array(
       '@attributes' => 
      array (
        'type' => 'current observations',
      ),
       'location' => 
      SimpleXMLElement::__set_state(array(
         'location-key' => 'point1',
         'point' => 
        SimpleXMLElement::__set_state(array(
           '@attributes' => 
          array (
            'latitude' => '42.88',
            'longitude' => '-85.52',
          ),
        )),
         'area-description' => 'Grand Rapids, Gerald R. Ford International Airport, MI',
         'height' => '794',
      )),
       'moreWeatherInformation' => 'http://www.nws.noaa.gov/data/obhistory/KGRR.html',
       'time-layout' => 
      SimpleXMLElement::__set_state(array(
         '@attributes' => 
        array (
          'time-coordinate' => 'local',
        ),
         'layout-key' => 'k-p1h-n1-1',
         'start-valid-time' => '2016-11-22T20:53:00-05:00',
      )),
       'parameters' => 
      SimpleXMLElement::__set_state(array(
         '@attributes' => 
        array (
          'applicable-location' => 'point1',
        ),
         'temperature' => 
        array (
          0 => 
          SimpleXMLElement::__set_state(array(
             '@attributes' => 
            array (
              'type' => 'apparent',
              'units' => 'Fahrenheit',
              'time-layout' => 'k-p1h-n1-1',
            ),
             'value' => '29',
          )),
          1 => 
          SimpleXMLElement::__set_state(array(
             '@attributes' => 
            array (
              'type' => 'dew point',
              'units' => 'Fahrenheit',
              'time-layout' => 'k-p1h-n1-1',
            ),
             'value' => '22',
          )),
        ),
         'humidity' => 
        SimpleXMLElement::__set_state(array(
           '@attributes' => 
          array (
            'type' => 'relative',
            'time-layout' => 'k-p1h-n1-1',
          ),
           'value' => '75',
        )),
         'weather' => 
        SimpleXMLElement::__set_state(array(
           '@attributes' => 
          array (
            'time-layout' => 'k-p1h-n1-1',
          ),
           'name' => 'Weather Type, Coverage, Intensity',
           'weather-conditions' => 
          array (
            0 => 
            SimpleXMLElement::__set_state(array(
               '@attributes' => 
              array (
                'weather-summary' => 'A Few Clouds',
              ),
            )),
            1 => 
            SimpleXMLElement::__set_state(array(
               'value' => 
              SimpleXMLElement::__set_state(array(
                 'visibility' => '10.00',
              )),
            )),
          ),
        )),
         'conditions-icon' => 
        SimpleXMLElement::__set_state(array(
           '@attributes' => 
          array (
            'type' => 'forecast-NWS',
            'time-layout' => 'k-p1h-n1-1',
          ),
           'name' => 'Conditions Icon',
           'icon-link' => 'http://forecast.weather.gov/newimages/medium/nfew.png',
        )),
         'direction' => 
        SimpleXMLElement::__set_state(array(
           '@attributes' => 
          array (
            'type' => 'wind',
            'units' => 'degrees true',
            'time-layout' => 'k-p1h-n1-1',
          ),
           'value' => '90',
        )),
         'wind-speed' => 
        array (
          0 => 
          SimpleXMLElement::__set_state(array(
             '@attributes' => 
            array (
              'type' => 'gust',
              'units' => 'knots',
              'time-layout' => 'k-p1h-n1-1',
            ),
             'value' => 'NA',
          )),
          1 => 
          SimpleXMLElement::__set_state(array(
             '@attributes' => 
            array (
              'type' => 'sustained',
              'units' => 'knots',
              'time-layout' => 'k-p1h-n1-1',
            ),
             'value' => '6',
          )),
        ),
         'pressure' => 
        SimpleXMLElement::__set_state(array(
           '@attributes' => 
          array (
            'type' => 'barometer',
            'units' => 'inches of mercury',
            'time-layout' => 'k-p1h-n1-1',
          ),
           'value' => '30.29',
        )),
      )),
    )),
  ),
))

Open in new window

0
 

Author Comment

by:IT_Architect
Comment Utility
Period-name is not a data field -- it's an attribute of the tag.  You can use the @attributes() method to tease it out.
Got it!
This function provides the attributes and values defined within an xml tag.
Note: SimpleXML has made a rule of adding iterative properties to most methods. They cannot be viewed using var_dump() or anything else which can examine objects.
Weird!
Also, if you ever find yourself in the position of producing XML for public consumption, please do two things...
(1) do not produce attributes
(2) do not produce XML -- make it JSON instead!
Now who is going to tell Weather.gov?

Just FYI, I actually am not making a dime on this.  It pays bills for a friend that is currently disabled, big bills, sold his house to move family in with a relative, his wife doesn't make much, and they have a special-needs child.  I normally just maintained a couple servers for him, defeating attacks, etc., but I'm not charging for that now.  It will probably be another 6 months before he will be back in the saddle.  It cannot be too soon.

Thanks for all of your amazing help!
0
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 500 total points
Comment Utility
I doubt we can tell Weather.gov anything.  Their thinking seems to have calcified around 2004.  Same with some of PHP's data structures.  Why in the world would you want a "resource" or an object with invisible attributes?  These are just very poor design decisions taken a long time ago by novice programmers.  We know better today, but it's too late to escape the ways of the past without introducing breaking changes into the language, so it can never get fixed.  This is one of the reasons that Facebook forked PHP and built its own high-performance language.

Anyway, it's good of you to try to help your friend out.  Here is how to get the attributes.  Moving parts start around line 200.
https://iconoun.com/demo/temp_it_architect.php
<?php // demo/temp_it_architect.php
/**
 * https://www.experts-exchange.com/questions/28984878/XML-Data-Missing-in-PHP-SimpleXML.html
 *
 * http://graphical.weather.gov/xml/
 * http://graphical.weather.gov/xml/rest.php
 */
error_reporting(E_ALL);
echo '<pre>';

// THIS IS THE API LOCATION OF THE RESOURCE FOR THE $xml VARIABLE
$url = 'http://forecast.weather.gov/MapClick.php?lat=43.03&lon=-85.55&FcstType=dwml&Submit=Submit';

// SHOW THE SAMPLE DATA FROM THE API
$xml = <<<EOD
<?xml version="1.0" encoding="ISO-8859-1"?>
<dwml version="1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://graphical.weather.gov/xml/DWMLgen/schema/DWML.xsd">
  <head>
    <product concise-name="dwmlByDay" operational-mode="developmental" srsName="WGS 1984">
      <creation-date refresh-frequency="PT1H">2016-11-22T21:04:18-05:00</creation-date>
     <category>current observations and forecast</category>
    </product>
    <source>
      <production-center>Grand Rapids, MI</production-center>
      <credit>http://www.weather.gov/grr/</credit>
      <more-information>http://www.nws.noaa.gov/forecasts/xml/</more-information>
    </source>
  </head>
  <data type="forecast">

  <location>
    <location-key>point1</location-key>
    <point latitude="43.02" longitude="-85.54"/>
    <area-description>3 Miles ESE Northview MI</area-description>
    <height datum="mean sea level" height-units="feet">659</height>
  </location>
<moreWeatherInformation applicable-location="point1">http://forecast.weather.gov/MapClick.php?lat=43.02&amp;lon=-85.54</moreWeatherInformation>
  <time-layout time-coordinate="local" summarization="12hourly">
    <layout-key>k-p12h-n14-1</layout-key>
      <start-valid-time period-name="Tonight">2016-11-22T21:00:00-05:00</start-valid-time>
      <start-valid-time period-name="Wednesday">2016-11-23T06:00:00-05:00</start-valid-time>
      <start-valid-time period-name="Wednesday Night">2016-11-23T18:00:00-05:00</start-valid-time>
      <start-valid-time period-name="Thanksgiving Day">2016-11-24T06:00:00-05:00</start-valid-time>
      <start-valid-time period-name="Thursday Night">2016-11-24T18:00:00-05:00</start-valid-time>
      <start-valid-time period-name="Friday">2016-11-25T06:00:00-05:00</start-valid-time>
      <start-valid-time period-name="Friday Night">2016-11-25T18:00:00-05:00</start-valid-time>
      <start-valid-time period-name="Saturday">2016-11-26T06:00:00-05:00</start-valid-time>
      <start-valid-time period-name="Saturday Night">2016-11-26T18:00:00-05:00</start-valid-time>
      <start-valid-time period-name="Sunday">2016-11-27T06:00:00-05:00</start-valid-time>
      <start-valid-time period-name="Sunday Night">2016-11-27T18:00:00-05:00</start-valid-time>
      <start-valid-time period-name="Monday">2016-11-28T06:00:00-05:00</start-valid-time>
      <start-valid-time period-name="Monday Night">2016-11-28T18:00:00-05:00</start-valid-time>
      <start-valid-time period-name="Tuesday">2016-11-29T06:00:00-05:00</start-valid-time>
  </time-layout>

  <time-layout time-coordinate="local" summarization="12hourly">
    <layout-key>k-p24h-n7-1</layout-key>
      <start-valid-time period-name="Tonight">2016-11-22T21:00:00-05:00</start-valid-time>
      <start-valid-time period-name="Wednesday Night">2016-11-23T18:00:00-05:00</start-valid-time>
      <start-valid-time period-name="Thursday Night">2016-11-24T18:00:00-05:00</start-valid-time>
      <start-valid-time period-name="Friday Night">2016-11-25T18:00:00-05:00</start-valid-time>
      <start-valid-time period-name="Saturday Night">2016-11-26T18:00:00-05:00</start-valid-time>
      <start-valid-time period-name="Sunday Night">2016-11-27T18:00:00-05:00</start-valid-time>
      <start-valid-time period-name="Monday Night">2016-11-28T18:00:00-05:00</start-valid-time>
  </time-layout>

  <time-layout time-coordinate="local" summarization="12hourly">
    <layout-key>k-p24h-n7-2</layout-key>
      <start-valid-time period-name="Wednesday">2016-11-23T06:00:00-05:00</start-valid-time>
      <start-valid-time period-name="Thanksgiving Day">2016-11-24T06:00:00-05:00</start-valid-time>
      <start-valid-time period-name="Friday">2016-11-25T06:00:00-05:00</start-valid-time>
      <start-valid-time period-name="Saturday">2016-11-26T06:00:00-05:00</start-valid-time>
      <start-valid-time period-name="Sunday">2016-11-27T06:00:00-05:00</start-valid-time>
      <start-valid-time period-name="Monday">2016-11-28T06:00:00-05:00</start-valid-time>
      <start-valid-time period-name="Tuesday">2016-11-29T06:00:00-05:00</start-valid-time>
  </time-layout>


  <parameters applicable-location="point1">

    <temperature type="minimum" units="Fahrenheit" time-layout="k-p24h-n7-1">
      <name>Daily Minimum Temperature</name>
        <value>28</value>
        <value>35</value>
        <value>34</value>
        <value>33</value>
        <value>31</value>
        <value>38</value>
        <value>38</value>
    </temperature>

    <temperature type="maximum" units="Fahrenheit" time-layout="k-p24h-n7-2">
      <name>Daily Maximum Temperature</name>
        <value>38</value>
        <value>44</value>
        <value>41</value>
        <value>44</value>
        <value>46</value>
        <value>48</value>
        <value>43</value>
    </temperature>

    <probability-of-precipitation  type="12 hour" units="percent" time-layout="k-p12h-n14-1">
      <name>12 Hourly Probability of Precipitation</name>
        <value>30</value>
        <value>80</value>
        <value>70</value>
        <value xsi:nil="true"></value>
        <value>30</value>
        <value>40</value>
        <value>20</value>
        <value xsi:nil="true"></value>
        <value xsi:nil="true"></value>
        <value xsi:nil="true"></value>
        <value xsi:nil="true"></value>
        <value xsi:nil="true"></value>
        <value xsi:nil="true"></value>
        <value xsi:nil="true"></value>
    </probability-of-precipitation>

    <weather time-layout="k-p12h-n14-1">
      <name>Weather Type, Coverage, Intensity</name>
        <weather-conditions weather-summary="Mostly Cloudy then Chance Wintry Mix"/>
        <weather-conditions weather-summary="Wintry Mix"/>
        <weather-conditions weather-summary="Rain Likely"/>
        <weather-conditions weather-summary="Cloudy"/>
        <weather-conditions weather-summary="Slight Chance Rain then Chance Rain/Snow"/>
        <weather-conditions weather-summary="Chance Showers"/>
        <weather-conditions weather-summary="Slight Chance Snow Showers"/>
        <weather-conditions weather-summary="Partly Sunny"/>
        <weather-conditions weather-summary="Partly Cloudy"/>
        <weather-conditions weather-summary="Partly Sunny"/>
        <weather-conditions weather-summary="Showers Likely"/>
        <weather-conditions weather-summary="Chance Showers"/>
        <weather-conditions weather-summary="Chance Showers then Rain/Snow Likely"/>
        <weather-conditions weather-summary="Chance Rain/Snow"/>
    </weather>

    <conditions-icon type="forecast-NWS" time-layout="k-p12h-n14-1">
      <name>Conditions Icon</name>        <icon-link>http://forecast.weather.gov/DualImage.php?i=nbkn&amp;j=nfzra_sn&amp;jp=30</icon-link>
        <icon-link>http://forecast.weather.gov/newimages/medium/fzra_sn80.png</icon-link>
        <icon-link>http://forecast.weather.gov/newimages/medium/nra70.png</icon-link>
        <icon-link>http://forecast.weather.gov/newimages/medium/ovc.png</icon-link>
        <icon-link>http://forecast.weather.gov/DualImage.php?i=nra&amp;j=nra_sn&amp;ip=20&amp;jp=30</icon-link>
        <icon-link>http://forecast.weather.gov/newimages/medium/shra40.png</icon-link>
        <icon-link>http://forecast.weather.gov/newimages/medium/nsn20.png</icon-link>
        <icon-link>http://forecast.weather.gov/newimages/medium/bkn.png</icon-link>
        <icon-link>http://forecast.weather.gov/newimages/medium/nsct.png</icon-link>
        <icon-link>http://forecast.weather.gov/newimages/medium/bkn.png</icon-link>
        <icon-link>http://forecast.weather.gov/newimages/medium/nshra.png</icon-link>
        <icon-link>http://forecast.weather.gov/newimages/medium/shra.png</icon-link>
        <icon-link>http://forecast.weather.gov/DualImage.php?i=nshra&amp;j=nra_sn&amp;ip=0&amp;jp=0</icon-link>
        <icon-link>http://forecast.weather.gov/newimages/medium/ra_sn.png</icon-link>
    </conditions-icon>

    <hazards time-layout="">
      <name>Watches, Warnings, and Advisories</name>
      <hazard-conditions>
        <hazard headline="Hazardous Weather Outlook">
          <hazardTextURL>http://forecast.weather.gov/showsigwx.php?warnzone=MIZ057&amp;warncounty=MIC081&amp;firewxzone=MIZ057&amp;local_place1=3+Miles+ESE+Northview+MI&amp;product1=Hazardous+Weather+Outlook</hazardTextURL>
        </hazard>
      </hazard-conditions>
    </hazards>

    <wordedForecast time-layout="k-p12h-n14-1" dataSource="grrNetcdf" wordGenerator="markMitchell">
      <name>Text Forecast</name>
        <text>A chance of snow and freezing rain, mainly after 3am.  Mostly cloudy, with a low around 28. East wind 7 to 9 mph.  Chance of precipitation is 30%.</text>
        <text>Rain likely, possibly mixed with snow and freezing rain before 7am, then rain and snow likely between 7am and 1pm, then rain after 1pm.  High near 38. East southeast wind 10 to 14 mph.  Chance of precipitation is 80%. Little or no ice accumulation expected.  Little or no snow accumulation expected. </text>
        <text>Rain likely, mainly before 1am.  Cloudy, with a low around 35. Southeast wind 5 to 10 mph becoming light  after midnight.  Chance of precipitation is 70%. New precipitation amounts between a tenth and quarter of an inch possible. </text>
        <text>Cloudy, with a high near 44. South southwest wind 5 to 7 mph becoming west in the afternoon. </text>
        <text>A slight chance of rain before 1am, then a chance of rain and snow.  Cloudy, with a low around 34. West wind around 6 mph.  Chance of precipitation is 30%.</text>
        <text>A 40 percent chance of showers.  Cloudy, with a high near 41.</text>
        <text>A 20 percent chance of snow showers before 1am.  Mostly cloudy, with a low around 33.</text>
        <text>Partly sunny, with a high near 44.</text>
        <text>Partly cloudy, with a low around 31.</text>
        <text>Partly sunny, with a high near 46.</text>
        <text>Showers likely.  Mostly cloudy, with a low around 38.</text>
        <text>A chance of showers.  Cloudy, with a high near 48.</text>
        <text>Rain and snow showers likely.  Mostly cloudy, with a low around 38.</text>
        <text>A chance of rain and snow showers.  Mostly cloudy, with a high near 43.</text>
    </wordedForecast>

</parameters>
</data>
<data type="current observations">
	<location>
		<location-key>point1</location-key>
		<point latitude="42.88" longitude="-85.52"/>
		<area-description>Grand Rapids, Gerald R. Ford International Airport, MI</area-description>
		<height datum="mean sea level" height-units="feet">794</height>
	</location>
	<moreWeatherInformation applicable-location="point1">http://www.nws.noaa.gov/data/obhistory/KGRR.html</moreWeatherInformation>	<time-layout time-coordinate="local">	<layout-key>k-p1h-n1-1</layout-key>	<start-valid-time period-name="current">2016-11-22T20:53:00-05:00</start-valid-time>	</time-layout>	<parameters applicable-location="point1">	<temperature type="apparent" units="Fahrenheit" time-layout="k-p1h-n1-1">	<value>29</value>	</temperature>	<temperature type="dew point" units="Fahrenheit" time-layout="k-p1h-n1-1">	<value>22</value>	</temperature>	<humidity type="relative" time-layout="k-p1h-n1-1">	<value>75</value>	</humidity>	<weather time-layout="k-p1h-n1-1">	<name>Weather Type, Coverage, Intensity</name>	<weather-conditions weather-summary="A Few Clouds"/>	<weather-conditions>	<value>	<visibility units="statute miles">10.00</visibility>	</value>	</weather-conditions>	</weather>	<conditions-icon type="forecast-NWS" time-layout="k-p1h-n1-1">	<name>Conditions Icon</name>	<icon-link>http://forecast.weather.gov/newimages/medium/nfew.png</icon-link>	</conditions-icon>	<direction type="wind" units="degrees true" time-layout="k-p1h-n1-1">	<value>90</value>	</direction>	<wind-speed type="gust" units="knots" time-layout="k-p1h-n1-1">	<value>NA</value>	</wind-speed>	<wind-speed type="sustained" units="knots" time-layout="k-p1h-n1-1">	<value>6</value>	</wind-speed>		<pressure type="barometer" units="inches of mercury" time-layout="k-p1h-n1-1">			<value>30.29</value>		</pressure>	</parameters></data></dwml>
EOD;


$obj = SimpleXML_Load_String($xml);

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

// SHOW HOW TO ACCESS SOME OF THE PROPERTIES
$cen = $obj->head->source->{'production-center'};
echo PHP_EOL . "CENTER: $cen";

$lat = (string)$obj->data[0]->location->point->attributes()->latitude;
$lon = (string)$obj->data[0]->location->point->attributes()->longitude;
$geo = "$lat,$lon";
echo PHP_EOL . "GEOCODE: $geo";

$lay = $obj->data->{'time-layout'};

// ITERATE OVER THE TIME LAYOUTS
foreach ($lay as $key => $val)
{
    // ITERATE OVER THE START VALID TIME
    foreach ($val->{'start-valid-time'} as $day)
    {
        // ISOLATE THE ISO-8601 DATE
        $iso = (string)$day;

        // ISOLATE THE DAY OF THE WEEK
        $dow = $day->attributes()->{'period-name'};

        echo PHP_EOL . "$iso $dow";
    }

    // ONLY PROCESS THE FIRST SET
    break;
}

Open in new window

Outputs:
CENTER: Grand Rapids, MI
GEOCODE: 43.02,-85.54
2016-11-22T21:00:00-05:00 Tonight
2016-11-23T06:00:00-05:00 Wednesday
2016-11-23T18:00:00-05:00 Wednesday Night
2016-11-24T06:00:00-05:00 Thanksgiving Day
2016-11-24T18:00:00-05:00 Thursday Night
2016-11-25T06:00:00-05:00 Friday
2016-11-25T18:00:00-05:00 Friday Night
2016-11-26T06:00:00-05:00 Saturday
2016-11-26T18:00:00-05:00 Saturday Night
2016-11-27T06:00:00-05:00 Sunday
2016-11-27T18:00:00-05:00 Sunday Night
2016-11-28T06:00:00-05:00 Monday
2016-11-28T18:00:00-05:00 Monday Night
2016-11-29T06:00:00-05:00 Tuesday

Open in new window

0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

Author Comment

by:IT_Architect
Comment Utility
This is one of the reasons that Facebook forked PHP and built its own high-performance language.
LOL!  Sounds like me.  Paradox, RBase, RBase, and everything else was so poorly thought out I couldn't get there from here.  I also built my own database.  When I deleted a record, I would post 255 to the first byte.  Whenever I looked something up with an index, and saw a 255, or a new record and didn't see it, I knew I had corruption and the file structure contained everything to rebuild the files and indexes.  I used Faircom CTree to maintain the B Trees.

I got it to work, but I want to study and understand your code because you know what you are doing a lot better than I.  This is what I did:
// *** Load Forecast start-valid-time and Forecast DayTitles into arrays
$ForecastTimes = array();	$ForecastTimesAttributes = array();  // Initialize to empty array()
$i = 0;
foreach ($fcst_StartValidTime_array as $item) {
    $ForecastTimes[$i] = (string)$item;
    $ForecastTimesAttributes[$i] = (string)$item->attributes();
    ++$i;
}
unset($item);

Open in new window

0
 

Author Comment

by:IT_Architect
Comment Utility
Thanks TONS and TONS for all of your help!  You are a master.

What I've observed about PHP over time is it is unsinkable, although many have tried, because of all of the code out there before any thing else came along.  IMO it would be cruel to write and maintain anything serious in PHP.  I've written two ERP packages for Tier-1 automotive suppliers that included quality systems with graphing and integration with and controlling machinery, rolled goods balancing, finite scheduling, time clocks, and EDI with the automakers and suppliers.  I'm used to declared variables that make it impossible for spelling mistakes, a compiler that does the type casting because it knows what the variables are, inheriting types and lengths from data dictionaries to prevent data corruption, rule-based automatic generation of middle ware and data checking, simpler and more standard OOP syntax, etc.
0
 

Author Closing Comment

by:IT_Architect
Comment Utility
He is amazing!
0
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
I think the "anything serious" part is behind us now.  Much of Yahoo, nearly all of Facebook (until last year) and large parts of Google are PHP machines.  Wikipedia, Flickr, Tumblr and every WordPress blog?  All PHP machines!  PHP supports APIs with 1900 hits per second per server and doesn't even break a sweat.  And all of that was built before PHP7, which approximately doubles the performance of the language.  Our current estimate is that PHP powers 1/4 of all data on the internet.

The central issue that haunts many PHP web sites is the age of the language and the astonishingly large collection of terrible code examples that litter the internet.  If you know a bit about computer science, you can build successful PHP apps.  But you can't just walk in the door and expect to find "best practices" all around you.  To the contrary, most of the code examples I've found online are full of holes.  For the new PHP programmer, it takes a while to learn what is good and what is not-so-good.  It doesn't help that you're dealing with a language that has more than 1,500 (procedural) functions!
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

728 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

14 Experts available now in Live!

Get 1:1 Help Now