Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: foreach - odczytywanie pojedynczego wpisu
Forum PHP.pl > Forum > PHP
lucas666
Witam. moj problem polega na tym, ze chce odczytac jeden, konkretny wpis z tablicy. Niestety, nizej zamieszczony kod wyswietla mi cala zawartosc tablicy...
Przejzalem manuala, ale nie moge sobie z tym poradzic;/
z gory dzieki za pomoc;)

  1. // set feed URL
  2. $feedURL = 'http://gdata.youtube.com/feeds/api/users/ladygagaofficial';
  3.  
  4. // read feed into SimpleXML object
  5. $sxml = simplexml_load_file($feedURL);
  6.  
  7. // iterate over entries in feed
  8. foreach ($sxml->entry as $entry) {
  9. // get nodes in media: namespace for media information
  10. $media = $entry->children('http://search.yahoo.com/mrss/');
  11.  
  12. // get video player URL
  13. $attrs = $media->group->player->attributes();
  14. $watch = $attrs['url'];
  15.  
  16. // get video thumbnail
  17. $attrs = $media->group->thumbnail[0]->attributes();
  18. $thumbnail = $attrs['url'];
  19.  
  20. // get <yt:duration> node for video length
  21. $yt = $media->children('http://gdata.youtube.com/schemas/2007');
  22. $attrs = $yt->duration->attributes();
  23. $length = $attrs['seconds'];
  24.  
  25. // get <yt:stats> node for viewer statistics
  26. $yt = $entry->children('http://gdata.youtube.com/schemas/2007');
  27. $attrs = $yt->statistics->attributes();
  28. $viewCount = $attrs['viewCount'];
  29.  
  30. // get <gd:rating> node for video ratings
  31. $gd = $entry->children('http://schemas.google.com/g/2005');
  32. if ($gd->rating) {
  33. $attrs = $gd->rating->attributes();
  34. $rating = $attrs['average'];
  35. } else {
  36. $rating = 0;
  37. }
  38.  
  39. echo $watch;
cycofiasz
  1. echo (string) $sxml->title;


Ale nie jestem pewien czy o to Ci chodzi bo takich przykładów w manualu jest cała masa.
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.