【发布时间】:2013-04-22 21:29:52
【问题描述】:
我的 php 代码使用 YouTube api 正确检索标题、视频网址、观看次数、视频日期、最后评论日期和描述的前 160 个字符。我似乎无法弄清楚如何获得整个描述。我知道它在检索到的 xml 中,因为我已经转储了它。那我怎么只得到 160 个字符?
整个描述被截断为 157 个字符,并添加了“...”,所以当我 echo 或 var_dump 时,它是 160 个字符。这是我的完整测试代码(没有标题、视频网址等)。
<?php
$feedURL = 'http://gdata.youtube.com/feeds/api/videos?q=phone&v=2&fields=entry[yt:statistics/@viewCount > 10000]&start-index=1&max-results=1';
$sxml = simplexml_load_file($feedURL);
foreach ($sxml->entry as $entry) {
$media = $entry->children('http://search.yahoo.com/mrss/');
echo $media->group->description;
}
?>
这是页面上显示的内容:
免费 TuTiTu 的游戏:http://www.tutitu.tv/index.php/games 免费的 TuTiTu 着色页:http://www.tutitu.tv/index.php/coloring 加入我们的 Facebook:https...
当我以这种方式获取 xml 时:
gdata.youtube.com/feeds/api/videos/JI-5kh_4gO0?v=2&alt=json-in-script&callback=youtubeFeedCallback&prettyprint=true
整个描述如下:
"media$description": {
"$t": "FREE TuTiTu's Games: http://www.tutitu.tv/index.php/games\nFREE TuTiTu's Coloring pages at: http://www.tutitu.tv/index.php/coloring\nJoin us on Facebook: https://www.facebook.com/TuTiTuTV\nTuTiTu's T-Shirts: http://www.zazzle.com/TuTiTu?rf=238778092083495163\n\nTuTiTu - The toys come to life\n\nTuTiTu - \"The toys come to life\" is a 3D animated television show targeting 2-3 year olds. Through colorful shapes TuTiTu will stimulate the children's imagination and creativity. On each episode TuTiTu's shapes will transform into a new and exciting toy.",
"type": "plain"
},
我确定我错过了一些基本的东西,但是当我寻找解决方案时,我没有找到它。
感谢您的帮助。
【问题讨论】:
标签: php youtube-api