joequah1 Posted September 13, 2011 Share Posted September 13, 2011 im trying to get data from xml using php. i only know the basic. can give tell me how to get data from this line <yweather:location city="Georgetown" region="" country="Malaysia"/> this is from a xml. i want to get the data of city and country. thanks. Link to comment https://forums.phpfreaks.com/topic/247029-get-data-from-xml-please-help/ Share on other sites More sharing options...
silkfire Posted September 13, 2011 Share Posted September 13, 2011 Use SimpleXML: $xml->location->attributes()->city Link to comment https://forums.phpfreaks.com/topic/247029-get-data-from-xml-please-help/#findComment-1268652 Share on other sites More sharing options...
salathe Posted September 13, 2011 Share Posted September 13, 2011 Lots of people stumble over namespaced nodes with SimpleXML (e.g. your yweather:location). The snippet below shows you how to get the location element and those attributes. $location = $xml->channel->children('yweather', true)->location->attributes(); $city = (string) $location->city; $country = (string) $location->country; echo "Got $city in $country."; More info: http://php.net/simplexmlelement.children http://php.net/simplexml.examples-basic Link to comment https://forums.phpfreaks.com/topic/247029-get-data-from-xml-please-help/#findComment-1268668 Share on other sites More sharing options...
joequah1 Posted September 19, 2011 Author Share Posted September 19, 2011 thank you for the helps. it solved my problems. Link to comment https://forums.phpfreaks.com/topic/247029-get-data-from-xml-please-help/#findComment-1270577 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.