开发者

Zend-framework: YouTube video link validation

is any method to validate Youtube video link with Zend-framework ?

If user inputs not valid link, for example http://www.youtube.com/watch?00zzv=nel how can I check it 开发者_JS百科before inserting into site ?


I'm pretty sure that there is no built in validator for this, but writing custom validators is super easy:

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;
    }

}

Just put whatever checks you need in that class, and run the validator on any Youtube links to be checked.

edit: From Laykes, you might want to consider using the validator to check if the video actually exists, instead of determining if it fits a pattern. Depends on your use cases though- eg how much latency do you want to introduce by making a call to the Youtube API?


I don't know if it is possible, however, I would take a different approach and try and see if the link has comments on it.

Take this for example. From here: 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";
}

If you use the video id in the VideoCommentFeed argument, you will be able to get the value in $commentFeed. If you then get an error, you know that the video does not exist.

I am sure if you try other methods you will probably find example what you want.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜