Display a user's YouTube videos


/ Published in: PHP
Save to your folder(s)

Uses the Magpie RSS library (http://magpierss.sourceforge.net/). I suppose I should be using the GData API, but this was a quicker solution for me.


Copy this code and paste it in your HTML
  1. require_once('magpierss/rss_fetch.inc');
  2. $rss = fetch_rss("http://www.youtube.com/rss/user/$username/videos.rss");
  3. foreach ($rss->items as $item) {
  4. preg_match('/http:\/\/(.*)default.jpg/',$item['description'],$matches);
  5. $thumb = $matches[0];
  6. $title = $item['title'];
  7. $link = $item['link'];
  8. $date = date("n/d/Y",strtotime($item['pubdate']));
  9. ?>
  10. <div class="video">
  11. <a href="<?php echo $link; ?>"><img src="<?php echo $thumb; ?>" /></a><br />
  12. <strong><?php echo $title; ?></strong><br />
  13. posted on <?php echo $date; ?>
  14. </div>
  15. <?php
  16. }
  17. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.