Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP]Odczyt z XML
Forum PHP.pl > Forum > Przedszkole
northwest
Witam serdecznie,
Mam następujący plik XML:
  1. This XML file does not appear to have any style information associated with it. The document tree is shown below.
  2. <weatherdata>
  3. <location>
  4. <name>Bedford</name>
  5. <type/>
  6. <country>GB</country>
  7. <timezone/>
  8. <location altitude="0" latitude="52.13459" longitude="-0.46632" geobase="geonames" geobaseid="0"/>
  9. </location>
  10. <credit/>
  11. <meta>
  12. <lastupdate/>
  13. <calctime>0.0627</calctime>
  14. <nextupdate/>
  15. </meta>
  16. <sun rise="2014-05-29T03:49:01" set="2014-05-29T20:09:37"/>
  17. <forecast>
  18. <time day="2014-05-29">
  19. <symbol number="803" name="broken clouds" var="04d"/>
  20. <precipitation/>
  21. <windDirection deg="91" code="E" name="East"/>
  22. <windSpeed mps="4.26" name="Gentle Breeze"/>
  23. <temperature day="18.57" min="14.5" max="19.22" night="14.5" eve="18.68" morn="18.57"/>
  24. <pressure unit="hPa" value="1019.32"/>
  25. <humidity value="97" unit="%"/>
  26. <clouds value="broken clouds" all="80" unit="%"/>
  27. </time>
  28. <time day="2014-05-30">
  29. <symbol number="803" name="broken clouds" var="04d"/>
  30. <precipitation/>
  31. <windDirection deg="76" code="ENE" name="East-northeast"/>
  32. <windSpeed mps="4.32" name="Gentle Breeze"/>
  33. <temperature day="17.94" min="12.47" max="18.4" night="12.47" eve="17.58" morn="13.08"/>
  34. <pressure unit="hPa" value="1027.45"/>
  35. <humidity value="90" unit="%"/>
  36. <clouds value="broken clouds" all="56" unit="%"/>
  37. </time>
  38. <time day="2014-05-31">
  39. <symbol number="802" name="scattered clouds" var="03d"/>
  40. <precipitation/>
  41. <windDirection deg="310" code="NW" name="Northwest"/>
  42. <windSpeed mps="2.21" name="Light breeze"/>
  43. <temperature day="17.28" min="11.48" max="18.91" night="11.48" eve="17.92" morn="12.28"/>
  44. <pressure unit="hPa" value="1029.33"/>
  45. <humidity value="94" unit="%"/>
  46. <clouds value="scattered clouds" all="36" unit="%"/>
  47. </time>
  48. <time day="2014-06-01">
  49. <symbol number="801" name="few clouds" var="02d"/>
  50. <precipitation/>
  51. <windDirection deg="43" code="NE" name="NorthEast"/>
  52. <windSpeed mps="2.06" name="Light breeze"/>
  53. <temperature day="18.47" min="12.99" max="19.21" night="14.57" eve="18.86" morn="12.99"/>
  54. <pressure unit="hPa" value="1027.11"/>
  55. <humidity value="95" unit="%"/>
  56. <clouds value="few clouds" all="20" unit="%"/>
  57. </time>
  58. <time day="2014-06-02">
  59. <symbol number="501" name="moderate rain" var="10d"/>
  60. <precipitation value="3.5" type="rain"/>
  61. <windDirection deg="183" code="S" name="South"/>
  62. <windSpeed mps="2.66" name="Light breeze"/>
  63. <temperature day="14.89" min="12.72" max="16.22" night="12.72" eve="16.21" morn="13.73"/>
  64. <pressure unit="hPa" value="1022.79"/>
  65. <humidity value="94" unit="%"/>
  66. <clouds value="overcast clouds" all="92" unit="%"/>
  67. </time>
  68. <time day="2014-06-03">
  69. <symbol number="500" name="light rain" var="10d"/>
  70. <precipitation value="0.87" type="rain"/>
  71. <windDirection deg="48" code="NE" name="NorthEast"/>
  72. <windSpeed mps="4.74" name="Gentle Breeze"/>
  73. <temperature day="17.53" min="11.04" max="17.59" night="11.04" eve="17.59" morn="13.49"/>
  74. <pressure unit="hPa" value="1019.6"/>
  75. <humidity value="0" unit="%"/>
  76. <clouds value="few clouds" all="12" unit="%"/>
  77. </time>
  78. <time day="2014-06-04">
  79. <symbol number="500" name="light rain" var="10d"/>
  80. <precipitation value="0.5" type="rain"/>
  81. <windDirection deg="359" code="" name=""/>
  82. <windSpeed mps="3.72" name="Gentle Breeze"/>
  83. <temperature day="17.59" min="10.99" max="17.72" night="10.99" eve="17.72" morn="12.78"/>
  84. <pressure unit="hPa" value="1014.63"/>
  85. <humidity value="0" unit="%"/>
  86. <clouds value="broken clouds" all="63" unit="%"/>
  87. </time>
  88. </forecast>
  89. </weatherdata>


Chciałbym pobrać informacje o pogodzie na dzisiaj oraz kolejne dni. Na dzisiaj pobieram następującym kodem:
  1. $map_url = ('http://www.serwer.pl/plik.xml');
  2. $xml_load = simplexml_load_file($map_url);
  3.  
  4. $tmp = $xml_load->forecast->time->symbol->attributes();
  5. $opis1 = $tmp['name']; // opis pogody
  6. $obrazek1 = $tmp['var']; // kod obrazka
  7.  
  8. $tmp = $xml_load->forecast->time->windDirection->attributes();
  9. $kierunek_wiatru = $tmp['code'];
  10. $kierunek_wiatru1 = $tmp['deg'].$kierunek_wiatru; // kierunek wiatru
  11.  
  12. $tmp = $xml_load->forecast->time->windSpeed->attributes();
  13. $szybkosc_wiatru1 = $tmp['mps']." mps"; // szybkość wiatru
  14.  
  15. $tmp = $xml_load->forecast->time->temperature->attributes();
  16. $temperatura1 = $tmp['day']."&#186"." C"; // temperatura
  17. $temperatura_min1 = $tmp['min']."&#186"." C"; // temperatura minimalna
  18. $temperatura_max1 = $tmp['max']."&#186"." C"; // temperatura maksymalna


W jaki sposób mogę pobrać na jutro/pojutrze itp?


bardzo proszę o pomoc,
Northwest
Pyton_000
  1. $tmp = $xml_load->xpath('/weatherdata/forecast/time');

zrób sobie Dump tego i zobaczysz co dostaniesz
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.