Autor | Zpráva | ||
---|---|---|---|
Tomast Profil |
#1 · Zasláno: 9. 7. 2011, 20:26:13
Našel jsem PHP xml children, ale vůbec z toho nejsem moudrej. Podařilo se mi vypsat text třeba z <title>Bla Bla</title>, ale nemůžu přijít na to, jak dostat z následujícho kódu chill, speed, atd...
XML: <?xml version="1.0" encoding="UTF-8" standalone="yes" ?> <rss version="2.0" xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"> <channel> <yweather:wind chill="30" direction="210" speed="8.05" /> <yweather:units temperature="C" distance="km" pressure="mb" speed="km/h"/> </channel> </rss> PHP: <? $feedURL = 'soubor.xml'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$feedURL); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_TIMEOUT, 4); $result = curl_exec($ch); $xml = simplexml_load_string($result); $channel=stripslashes($xml->channel->item); ?> Poradí nějaký XML odoborník? Díky. |
||
DJ Miky Profil |
#2 · Zasláno: 9. 7. 2011, 21:27:31
Ke jmenným prostorům se dostaneš takto:
$namespaces = $channel->getNameSpaces(true); $yweather = $channel->children($namespaces['yweather']); // pak se dostaneš k $yweather->wind a $yweather->units K atributům (chill, direction atd.) se dostaneš pomocí metody attributes(), např.: echo $yweather->wind->attributes()->chill; echo $yweather->wind->attributes()->direction; |
||
Časová prodleva: 13 let
|
0