Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [XML][PHP]pobieranie wartość z XML za pomocą xpath
pabito
post
Post #1





Grupa: Zarejestrowani
Postów: 77
Pomógł: 4
Dołączył: 14.05.2013

Ostrzeżenie: (0%)
-----


Witam
Mam taką strukturę, w jaki sposób mogę pobrać datę(data_eveniment) tylko dlatego obiektu gdzie cod_eveniment = "OK"

  1. array(5) {
  2. [0]=>
  3. object(SimpleXMLElement)#2 (7) {
  4. ["data_eveniment"]=>
  5. string(19) "2014-06-25T10:37:20"
  6. ["centru"]=>
  7. string(9) "BUCURESTI"
  8. ["cod_eveniment"]=>
  9. string(2) "OK"
  10. ["descriere_eveniment"]=>
  11. string(7) "Livrata"
  12. ["persoana_livrare"]=>
  13. string(16) "renato pesamosca"
  14. ["observatii_livrare"]=>
  15. object(SimpleXMLElement)#7 (0) {
  16. }
  17. ["motiv"]=>
  18. object(SimpleXMLElement)#8 (0) {
  19. }
  20. }
  21. [1]=>
  22. object(SimpleXMLElement)#3 (7) {
  23. ["data_eveniment"]=>
  24. string(19) "2014-06-25T08:52:42"
  25. ["centru"]=>
  26. string(9) "BUCURESTI"
  27. ["cod_eveniment"]=>
  28. string(2) "WC"
  29. ["descriere_eveniment"]=>
  30. string(15) "Spre destinatar"
  31. ["persoana_livrare"]=>
  32. object(SimpleXMLElement)#8 (0) {
  33. }
  34. ["observatii_livrare"]=>
  35. object(SimpleXMLElement)#7 (0) {
  36. }
  37. ["motiv"]=>
  38. object(SimpleXMLElement)#9 (0) {
  39. }
  40. }
  41. [2]=>
  42. object(SimpleXMLElement)#4 (7) {
  43. ["data_eveniment"]=>
  44. string(19) "2014-06-25T00:22:37"
  45. ["centru"]=>
  46. string(9) "BUCURESTI"
  47. ["cod_eveniment"]=>
  48. string(2) "AR"
  49. ["descriere_eveniment"]=>
  50. string(26) "Sosit In Statia de Livrare"
  51. ["persoana_livrare"]=>
  52. object(SimpleXMLElement)#9 (0) {
  53. }
  54. ["observatii_livrare"]=>
  55. object(SimpleXMLElement)#7 (0) {
  56. }
  57. ["motiv"]=>
  58. object(SimpleXMLElement)#8 (0) {
  59. }
  60. }
  61. [3]=>
  62. object(SimpleXMLElement)#5 (7) {
  63. ["data_eveniment"]=>
  64. string(19) "2014-06-24T20:05:48"
  65. ["centru"]=>
  66. string(7) "CRAIOVA"
  67. ["cod_eveniment"]=>
  68. string(2) "DF"
  69. ["descriere_eveniment"]=>
  70. string(17) "Plecat din Centru"
  71. ["persoana_livrare"]=>
  72. object(SimpleXMLElement)#8 (0) {
  73. }
  74. ["observatii_livrare"]=>
  75. object(SimpleXMLElement)#7 (0) {
  76. }
  77. ["motiv"]=>
  78. object(SimpleXMLElement)#9 (0) {
  79. }
  80. }
  81. [4]=>
  82. object(SimpleXMLElement)#6 (7) {
  83. ["data_eveniment"]=>
  84. string(19) "2014-06-24T18:31:25"
  85. ["centru"]=>
  86. string(7) "CRAIOVA"
  87. ["cod_eveniment"]=>
  88. string(2) "CI"
  89. ["descriere_eveniment"]=>
  90. string(22) "Receptionat in depozit"
  91. ["persoana_livrare"]=>
  92. object(SimpleXMLElement)#9 (0) {
  93. }
  94. ["observatii_livrare"]=>
  95. object(SimpleXMLElement)#7 (0) {
  96. }
  97. ["motiv"]=>
  98. object(SimpleXMLElement)#8 (0) {
  99. }
  100. }
  101. }


Ten post edytował pabito 28.06.2014, 14:59:31
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
tzm
post
Post #2





Grupa: Zarejestrowani
Postów: 675
Pomógł: 58
Dołączył: 17.12.2013

Ostrzeżenie: (10%)
X----


Zawsze chyba lepiej użyć wydajniejszej metody, bić się nie bije. Dyskutuję.. od tego jest forum.
A gdzie mam wrzucisz count? coś musi zliczyć elementy tablicy a bez sensu jest pisanie czegoś w stylu:

  1. $x = count($array);
  2. for($i = 0;$i <$x;$i++){}


To samo a mniej kodu jak zapisuję count($x).

Jak nie podajesz stringów w "" to wywala notice:

  1. Notice: Use of undefined constant data_eveniment - assumed 'data_eveniment' in C:\xampp\htdocs\encom\arr1.php on line 11

Go to the top of the page
+Quote Post
Pyton_000
post
Post #3





Grupa: Zarejestrowani
Postów: 8 068
Pomógł: 1414
Dołączył: 26.10.2005

Ostrzeżenie: (0%)
-----


Cytat(mitorski @ 28.06.2014, 16:31:23 ) *
Zawsze chyba lepiej użyć wydajniejszej metody, bić się nie bije. Dyskutuję.. od tego jest forum.
A gdzie mam wrzucisz count? coś musi zliczyć elementy tablicy a bez sensu jest pisanie czegoś w stylu:

  1. $x = count($array);
  2. for($i = 0;$i <$x;$i++){}


To samo a mniej kodu jak zapisuję count($x).

Jak nie podajesz stringów w "" to wywala notice:

  1. Notice: Use of undefined constant data_eveniment - assumed 'data_eveniment' in C:\xampp\htdocs\encom\arr1.php on line 11


Hehe i pisze to człowiek który posiłkuje się stroną która jest czysto informacyjna. Ba ale zobaczywszy jeden kawałek jaki to for jest szybszy od foreach nie doczytawszy do końca wsadza babol który powoduje spooory narzut wydajności (IMG:style_emoticons/default/wink.gif) Zresztą kolega wyżej już to skomentował.

Jak już chcesz używać for to tak:
  1. for($i=0, $x=count($cos); $i<$x; $x++)
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 6.10.2025 - 10:18