How to Parse XML's Media:Content with PHP?

前端 未结 2 434
南旧
南旧 2021-01-05 14:10

I\'ve found a great tutorial on how to accomplish most of the work at:

https://www.developphp.com/video/PHP/simpleXML-Tutorial-Learn-to-Parse-XML-Files-and-RSS-Feeds

2条回答
  •  离开以前
    2021-01-05 15:08

    Simple example for newbs like me:

    $url = "https://www.youtube.com/feeds/videos.xml?channel_id=UCwNPPl_oX8oUtKVMLxL13jg";
    $rss = simplexml_load_file($url);
    
    foreach($rss->entry as $item) {
    
      $time = $item->published;
      $time = date('Y-m-d \ H:i', strtotime($time));
    
      $media_group = $item->children( 'media', true );
      $title = $media_group->group->title;
      $description = $media_group->group->description;
      $views = $media_group->group->community->statistics->attributes()['views'];
    }
    echo $time . ' :: ' . $title . '
    ' . $description . '
    ' . $views . '
    ';

提交回复
热议问题