0

我使用下面的代码来检索最近 youtube 对视频的评论:

<?php
$videoId='lWA2pjMjpBs';
$url="http://gdata.youtube.com/feeds/api/videos/{$videoId}/comments";
$comments=simplexml_load_file($url);
foreach($comments->entry as $comment)
{
 echo '<fieldset>'.$comment->content.'</fieldset>';
}
?>

我有 2 个问题:1)有没有办法限制评论的数量,所以我只能显示示例 10 评论?2) 是否可以排除标记为垃圾邮件的评论?

谢谢。

4

1 回答 1

1

我不知道垃圾邮件,但你可以限制 nr。带有这样的客户端解决方案的评论:

$maxcomments = 10; //set max here
$commentcounter = 0; //add this

foreach($comments->entry as $comment)
{
   if($commentcounter < $maxcomments)
   {
       echo '<fieldset>'.$comment->content.'</fieldset>';
   }

   $commentcounter++;
}

没有检查这个,但它应该工作。我希望这会有所帮助。

于 2012-11-17T11:09:50.533 回答