php – 从xml中检索vimeo视频信息

我想从Vimeo的
XML API输出中获取数据.

在Vimeo中,如果我们加载此URL:http://vimeo.com/api/v2/video/30055721.xml,视频ID为30055721,它将在浏览器中输出XML数据(单行XML块):

<?xml version="1.0" encoding="UTF-8"?><videos><video><id>30055721</id><title>[MV]I-ny(아이니) 뮤직비디오</title><description>눈부신 가을 하늘을 닮은 목소리의 주인공 '아이니(i-ny)',  &lt;br /&gt;  그녀의 이름을 노래하다.</description><url>http://vimeo.com/30055721</url><upload_date>2011-10-04 22:34:19</upload_date><mobile_url>http://vimeo.com/m/30055721</mobile_url><thumbnail_small>http://b.vimeocdn.com/ts/201/671/201671639_100.jpg</thumbnail_small><thumbnail_medium>http://b.vimeocdn.com/ts/201/671/201671639_200.jpg</thumbnail_medium><thumbnail_large>http://b.vimeocdn.com/ts/201/671/201671639_640.jpg</thumbnail_large><user_id>2991448</user_id><user_name>Deviljoon</user_name><user_url>http://vimeo.com/user2991448</user_url><user_portrait_small>http://b.vimeocdn.com/ps/217/387/2173872_30.jpg</user_portrait_small><user_portrait_medium>http://b.vimeocdn.com/ps/217/387/2173872_75.jpg</user_portrait_medium><user_portrait_large>http://b.vimeocdn.com/ps/217/387/2173872_100.jpg</user_portrait_large><user_portrait_huge>http://b.vimeocdn.com/ps/217/387/2173872_300.jpg</user_portrait_huge><stats_number_of_likes>3</stats_number_of_likes><stats_number_of_plays>542</stats_number_of_plays><stats_number_of_comments>0</stats_number_of_comments><duration>235</duration><width>1280</width><height>720</height><tags>I-ny, 아이니, 뮤직비디오, music video, MV, kpop, k-pop, 550d</tags><embed_privacy>anywhere</embed_privacy></video></videos> 

但我想动态检索XML字段中的数据,以便在我的网页中显示它.

最佳答案 查看本文以获得完整的贯穿:

http://ditio.net/2008/06/19/using-php-curl-to-read-rss-feed-xml/

这应该可以让您了解如何将XML内容提取到PHP脚本中,然后将XML的内容解析为PHP.您需要对解析Feed的过程进行一些调整,特定于vimeo输出,但您应该只需通过播放即可完成此操作.

例如以下将输出ID.

$ch = curl_init("http://vimeo.com/api/v2/video/30055728.xml");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
$data = curl_exec($ch);
curl_close($ch);
$xml= new SimpleXmlElement($data, LIBXML_NOCDATA);
echo "<strong>".$xml->video->id."</strong>";

一旦建立了$xml,只需将$xml-> video-> id更改为您想要的任何节点(十字形’id’部分’).

点赞