wilm1998
03-09-2009, 08:44 PM
I am pulling in xml data from the National Weather Service to my php5 file.
I can pull the temperature data: $xml->data->parameters->temperature[0]->value;
However, I can not pull in the wave height data because the element id name includes a dash:
$xml->data->parameters->water-state[0]->waves[0]->value;
It appears to me I should use str_replace() to replace water-state with water_state. Unfortunately, I've been unsuccessful in my attempts. Not sure if I'm applying it incorrectly or if I need to use a different approach.
Here is the code I'm using. Please help me apply the str_replace() function correctly or suggest a different approach. Thank you.
<?php
$xml = simplexml_load_file("http://www.weather.gov/forecasts/xml/SOAP_server/ndfdXMLclient.php?whichClient=NDFDgen&lat=32.84&lon=-117.26&listLatLon=&lat1=&lon1=&lat2=&lon2=&resolutionSub=&listLat1=&listLon1=&listLat2=&listLon2=&resolutionList=&endPoint1Lat=&endPoint1Lon=&endPoint2Lat=&endPoint2Lon=&listEndPoint1Lat=&listEndPoint1Lon=&listEndPoint2Lat=&listEndPoint2Lon=&zipCodeList=&listZipCodeList=¢erPointLat=¢erPointLon=&distanceLat=&distanceLon=&resolutionSquare=&listCenterPointLat=&listCenterPointLon=&listDistanceLat=&listDistanceLon=&listResolutionSquare=&citiesLevel=&listCitiesLevel=§or=&gmlListLatLon=&featureType=&requestedTime=&startTime=&endTime=&compType=&propertyName=&product=time-series&begin=2004-01-01T00%3A00%3A00&end=2013-03-03T00%3A00%3A00&maxt=maxt&waveh=waveh&Submit=Submit");
?>
<?php echo $xml->data->parameters->temperature[0]->value; ?> °<br />
<?php echo $xml->data->parameters->water_state[0]->waves[0]->value; ?> Feet
I can pull the temperature data: $xml->data->parameters->temperature[0]->value;
However, I can not pull in the wave height data because the element id name includes a dash:
$xml->data->parameters->water-state[0]->waves[0]->value;
It appears to me I should use str_replace() to replace water-state with water_state. Unfortunately, I've been unsuccessful in my attempts. Not sure if I'm applying it incorrectly or if I need to use a different approach.
Here is the code I'm using. Please help me apply the str_replace() function correctly or suggest a different approach. Thank you.
<?php
$xml = simplexml_load_file("http://www.weather.gov/forecasts/xml/SOAP_server/ndfdXMLclient.php?whichClient=NDFDgen&lat=32.84&lon=-117.26&listLatLon=&lat1=&lon1=&lat2=&lon2=&resolutionSub=&listLat1=&listLon1=&listLat2=&listLon2=&resolutionList=&endPoint1Lat=&endPoint1Lon=&endPoint2Lat=&endPoint2Lon=&listEndPoint1Lat=&listEndPoint1Lon=&listEndPoint2Lat=&listEndPoint2Lon=&zipCodeList=&listZipCodeList=¢erPointLat=¢erPointLon=&distanceLat=&distanceLon=&resolutionSquare=&listCenterPointLat=&listCenterPointLon=&listDistanceLat=&listDistanceLon=&listResolutionSquare=&citiesLevel=&listCitiesLevel=§or=&gmlListLatLon=&featureType=&requestedTime=&startTime=&endTime=&compType=&propertyName=&product=time-series&begin=2004-01-01T00%3A00%3A00&end=2013-03-03T00%3A00%3A00&maxt=maxt&waveh=waveh&Submit=Submit");
?>
<?php echo $xml->data->parameters->temperature[0]->value; ?> °<br />
<?php echo $xml->data->parameters->water_state[0]->waves[0]->value; ?> Feet