Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Pobieranie filmów (array)
Forum PHP.pl > Forum > Przedszkole
unw
Witam. Mam krótki skrypt, dzięki któremu pobieram wszystkie najnowsze filmy z redtube. Wyświetla mi się ich ok. 10 jako print_r

Mam tablicę array wszystkich filmów np:

  1. Array
  2. (
  3. [videos] => Array
  4. (
  5. [0] => Array
  6. (
  7. [video] => Array
  8. (
  9. [duration] => 7:31
  10. [views] => 102
  11. [video_id] => 1359620
  12. [rating] => 0.00
  13. [ratings] => 0
  14. [title] => Big Titted MILF Rachel Love Trying Young Bull
  15. [url] => <a href="http://www.redtube.com/1359620" target="_blank">http://www.redtube.com/1359620</a>
  16. [embed_url] => <a href="http://embed.redtube.com/?id=1359620" target="_blank">http://embed.redtube.com/?id=1359620</a>
  17. [default_thumb] => <a href="http://img.l3.cdn.redtubefiles.com/_thumbs/0001359/1359620/1359620_015m.jpg" target="_blank">http://img.l3.cdn.redtubefiles.com/_thumbs...359620_015m.jpg</a>
  18. [thumb] => <a href="http://img.l3.cdn.redtubefiles.com/_thumbs/0001359/1359620/1359620_015m.jpg" target="_blank">http://img.l3.cdn.redtubefiles.com/_thumbs...359620_015m.jpg</a>
  19. [publish_date] => 2015-11-13 14:32:08
  20. [thumbs] => Array
  21. (
  22. [0] => Array
  23. (
  24. [size] => big
  25. [width] => 432
  26. [height] => 324
  27. [src] => <a href="http://img.l3.cdn.redtubefiles.com/_thumbs/0001359/1359620/1359620_001b.jpg" target="_blank">http://img.l3.cdn.redtubefiles.com/_thumbs...359620_001b.jpg</a>
  28. )
  29.  
  30. [1] => Array
  31. (
  32. [size] => big
  33. [width] => 432
  34. [height] => 324
  35. [src] => <a href="http://img.l3.cdn.redtubefiles.com/_thumbs/0001359/1359620/1359620_002b.jpg" target="_blank">http://img.l3.cdn.redtubefiles.com/_thumbs...359620_002b.jpg</a>
  36. )
  37.  
  38. [2] => Array
  39. (
  40. [size] => big
  41. [width] => 432
  42. [height] => 324
  43. [src] => <a href="http://img.l3.cdn.redtubefiles.com/_thumbs/0001359/1359620/1359620_003b.jpg" target="_blank">http://img.l3.cdn.redtubefiles.com/_thumbs...359620_003b.jpg</a>
  44. )
  45.  
  46. [3] => Array
  47. (
  48. [size] => big
  49. [width] => 432
  50. [height] => 324
  51. [src] => <a href="http://img.l3.cdn.redtubefiles.com/_thumbs/0001359/1359620/1359620_004b.jpg" target="_blank">http://img.l3.cdn.redtubefiles.com/_thumbs...359620_004b.jpg</a>
  52. )
  53.  
  54. [4] => Array
  55. (
  56. [size] => big
  57. [width] => 432
  58. [height] => 324
  59. [src] => <a href="http://img.l3.cdn.redtubefiles.com/_thumbs/0001359/1359620/1359620_005b.jpg" target="_blank">http://img.l3.cdn.redtubefiles.com/_thumbs...359620_005b.jpg</a>
  60. )
  61.  
  62. [5] => Array
  63. (
  64. [size] => big
  65. [width] => 432
  66. [height] => 324
  67. [src] => <a href="http://img.l3.cdn.redtubefiles.com/_thumbs/0001359/1359620/1359620_006b.jpg" target="_blank">http://img.l3.cdn.redtubefiles.com/_thumbs...359620_006b.jpg</a>
  68. )
  69.  
  70. [6] => Array
  71. (
  72. [size] => big
  73. [width] => 432
  74. [height] => 324
  75. [src] => <a href="http://img.l3.cdn.redtubefiles.com/_thumbs/0001359/1359620/1359620_007b.jpg" target="_blank">http://img.l3.cdn.redtubefiles.com/_thumbs...359620_007b.jpg</a>
  76. )
  77.  
  78. [7] => Array
  79. (
  80. [size] => big
  81. [width] => 432
  82. [height] => 324
  83. [src] => <a href="http://img.l3.cdn.redtubefiles.com/_thumbs/0001359/1359620/1359620_008b.jpg" target="_blank">http://img.l3.cdn.redtubefiles.com/_thumbs...359620_008b.jpg</a>
  84. )
  85.  
  86. [8] => Array
  87. (
  88. [size] => big
  89. [width] => 432
  90. [height] => 324
  91. [src] => <a href="http://img.l3.cdn.redtubefiles.com/_thumbs/0001359/1359620/1359620_009b.jpg" target="_blank">http://img.l3.cdn.redtubefiles.com/_thumbs...359620_009b.jpg</a>
  92. )
  93.  
  94. [9] => Array
  95. (
  96. [size] => big
  97. [width] => 432
  98. [height] => 324
  99. [src] => <a href="http://img.l3.cdn.redtubefiles.com/_thumbs/0001359/1359620/1359620_010b.jpg" target="_blank">http://img.l3.cdn.redtubefiles.com/_thumbs...359620_010b.jpg</a>
  100. )
  101.  
  102. [10] => Array
  103. (
  104. [size] => big
  105. [width] => 432
  106. [height] => 324
  107. [src] => <a href="http://img.l3.cdn.redtubefiles.com/_thumbs/0001359/1359620/1359620_011b.jpg" target="_blank">http://img.l3.cdn.redtubefiles.com/_thumbs...359620_011b.jpg</a>
  108. )
  109.  
  110. [11] => Array
  111. (
  112. [size] => big
  113. [width] => 432
  114. [height] => 324
  115. [src] => <a href="http://img.l3.cdn.redtubefiles.com/_thumbs/0001359/1359620/1359620_012b.jpg" target="_blank">http://img.l3.cdn.redtubefiles.com/_thumbs...359620_012b.jpg</a>
  116. )
  117.  
  118. [12] => Array
  119. (
  120. [size] => big
  121. [width] => 432
  122. [height] => 324
  123. [src] => <a href="http://img.l3.cdn.redtubefiles.com/_thumbs/0001359/1359620/1359620_013b.jpg" target="_blank">http://img.l3.cdn.redtubefiles.com/_thumbs...359620_013b.jpg</a>
  124. )
  125.  
  126. [13] => Array
  127. (
  128. [size] => big
  129. [width] => 432
  130. [height] => 324
  131. [src] => <a href="http://img.l3.cdn.redtubefiles.com/_thumbs/0001359/1359620/1359620_014b.jpg" target="_blank">http://img.l3.cdn.redtubefiles.com/_thumbs...359620_014b.jpg</a>
  132. )
  133.  
  134. [14] => Array
  135. (
  136. [size] => big
  137. [width] => 432
  138. [height] => 324
  139. [src] => <a href="http://img.l3.cdn.redtubefiles.com/_thumbs/0001359/1359620/1359620_015b.jpg" target="_blank">http://img.l3.cdn.redtubefiles.com/_thumbs...359620_015b.jpg</a>
  140. )
  141.  
  142. [15] => Array
  143. (
  144. [size] => big
  145. [width] => 432
  146. [height] => 324
  147. [src] => <a href="http://img.l3.cdn.redtubefiles.com/_thumbs/0001359/1359620/1359620_016b.jpg" target="_blank">http://img.l3.cdn.redtubefiles.com/_thumbs...359620_016b.jpg</a>
  148. )
  149.  
  150. )
  151.  
  152. [tags] => Array
  153. (
  154. [0] => Array
  155. (
  156. [tag_name] => Big Tits
  157. )
  158.  
  159. [1] => Array
  160. (
  161. [tag_name] => HD
  162. )
  163.  
  164. [2] => Array
  165. (
  166. [tag_name] => MILF
  167. )
  168.  
  169. )
  170.  
  171. )
  172.  
  173. )



w jaki sposób zrobić, aby zawartość wyświetlić i w odpowiednich miejscach przypisać np czas filmu, tytuł, obrazki?
nospor
Zamiast ogladac te filmy wzialbys sie pouczyl troche podstaw....
Manual php -> typy -> tablice
Tam masz wszystkie niezbedne informacje jak operowac na tablicach

przenosze
unw
akurat nie oglądam a pracuje nad takim serwisem który by te filmy zapisywał do bazy.

Skrypt wygląda tak:

  1. function redtube_search($search, $page) {
  2. $feedurl = 'http://api.redtube.com/?data=redtube.Videos.searchVideos&output=json&search='.$search.'&thumbsize=big&page='.$page;
  3. $ch = curl_init();
  4. $timeout = 15;
  5. curl_setopt($ch,CURLOPT_URL,$feedurl);
  6. curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
  7. curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  8. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
  9. $data = curl_exec($ch);
  10. curl_close($ch);
  11. $content = json_decode($data,true);
  12. return $content;
  13. }
  14.  
  15. $videos = redtube_search('teen',1);
  16.  
  17. print_r($videos);


ktoś pomoże, jak przypisać np tytuł, długość filmu, obrazek do zmiennej?
RaiZeN
foreach()
IProSoft
Pomóc ktoś może ale nikt za Ciebie tego nie zrobi, nie ten dział.

Przeczytaj o pętli i iterowaniu tablicy w PHP np. przez foreach
unw
wykombinowałem coś takiego:

  1. foreach($videos['videos'] as $v){
  2.  
  3. $title = $v['video']['title'];


pobieram tytuł, description, czas filmu itd bez problemu
teraz mam pytanie:


w jaki sposób pobrać
  1. [thumbs] => Array
  2. (
  3. [0] => Array
  4. (
  5. [size] => big
  6. [width] => 432
  7. [height] => 324
  8. [src] => <a href="http://img.l3.cdn.redtubefiles.com/_thumbs/0001359/1359649/1359649_001b.jpg" target="_blank">http://img.l3.cdn.redtubefiles.com/_thumbs...359649_001b.jpg</a>
  9. )


właśnie to src?
IProSoft
Tak samo jak inne, używając indeksu
  1. $title = $v['video']['thumbs'][0]['src'];
unw
ok zrobiłem coś takiego:


  1.  
  2. function redtube_search($search, $page) {
  3. $feedurl = 'http://api.redtube.com/?data=redtube.Videos.searchVideos&output=json&search='.$search.'&thumbsize=big&page='.$page;
  4. $ch = curl_init();
  5. $timeout = 15;
  6. curl_setopt($ch,CURLOPT_URL,$feedurl);
  7. curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
  8. curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  9. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
  10. $data = curl_exec($ch);
  11. curl_close($ch);
  12. $content = json_decode($data,true);
  13. return $content;
  14. }
  15. for($i = 1; $i <= 10; ++$i)
  16. {
  17. $videos = redtube_search($co,$i);
  18.  
  19. //print_r($videos);
  20.  
  21. foreach($videos['videos'] as $v){
  22. // title, thumbs, duration?
  23. $title = $v['video']['title'];
  24. }
  25. }
  26.  


Zrobiłem, że wyświetla mi od 1 do 10 strony. W jaki sposób mogę zrobić stronnicowanie? tak, aby wszystko co mi pobrało podzieliło np po 10 wpisów? a później mogę sobie klikać np 2 strona itd.

RaiZeN
google > php paginacja

a jak chcesz to masz tu moj stary i bardzo nieoptymalny kod od stronicowania: http://pastebin.com/xPwXfkZG
i od guzikow do przelaczania: http://pastebin.com/chdKwGCQ
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.