有没有什么方法可以用Zend-framework验证Youtube视频链接?
如果用户输入无效链接,例如http://www.youtube.com/watch?00zzv=nel,我如何在插入到站点之前检查它?
发布于 2010-02-24 01:17:17
我很确定没有内置的验证器,但编写自定义验证器非常容易:
class My_Validate_Youtube extends Zend_Validate_Abstract{
public function isValid($value){
// check url here
if (no_good($value)){
$this->_error("Explain the error here");
return false;
}
return true;
}
}只需在该类中放置您需要的任何检查,并在要检查的任何Youtube链接上运行验证器。
编辑:来自Laykes的,你可能想要考虑使用验证器来检查视频是否确实存在,而不是确定它是否符合模式。这取决于你的用例--例如,你想通过调用Youtube API引入多长的延迟?
发布于 2010-02-24 01:11:34
我不知道这是否可能,但是,我会采取不同的方法,并尝试看看该链接是否有评论。
以此为例。从这里:http://framework.zend.com/manual/en/zend.gdata.youtube.html
$yt = new Zend_Gdata_YouTube();
$commentFeed = $yt->getVideoCommentFeed('abc123813abc');
foreach ($commentFeed as $commentEntry) {
echo $commentEntry->title->text . "\n";
echo $commentEntry->content->text . "\n\n\n";
}如果在VideoCommentFeed参数中使用视频id,则可以在$commentFeed中获得该值。如果您随后得到一个错误,您就知道视频不存在。
我敢肯定,如果你尝试其他方法,你可能会找到你想要的例子。
https://stackoverflow.com/questions/2320116
复制相似问题