通过url id验证youtube视频
I am using php and yt API to determine if a video exists. I have implemented two functions two help me along this cause. The issues is with the function isYoutubeVideo
is returning me null value when a video is valid or invalid. I have checked its paremeters but I am still not sure why is giving me null value. Do i have the isYoutubeVideo
function set up wrong/missing something/needs change?
function isYoutubeVideo($formatted_url) {
$isValid = false;
if (isValidURL($formatted_url)) {
$idLength = 11;
$idStarts = strpos($formatted_url, "?v=");
if ($idStarts === FALSE) {
$idStarts = strpos($formatted_url, "&v=");
}
if ($idStarts !== FALSE) {
//there is a videoID present, now validate it
$v = substr($formatted_url, $idStarts, $idLength);
$headers = get_headers('http://gdata.youtube.com/feeds/api/videos/' . $videoID);
//did the request return a http code of 2xx?
if (!strpos($headers[0], '200')) {
$isValid = true;
}
}
}
return $isValid;
我使用php和yt API来确定视频是否存在。 我已经实现了两个功能,两个帮助我这个原因。 问题是函数 isYoutubeVideo code>在视频有效或无效时返回null值。 我检查了它的参数,但我仍然不确定为什么给我空值。 我是否有
isYoutubeVideo code>功能设置错误/缺少某些/需要更改? p>
function isYoutubeVideo($ formatted_url){
$ isValid = false;
if(isValidURL($ formatted_url)){
$ idLength = 11;
$ idStarts = strpos($ formatted_url,“?v =”);
if($ idStarts === FALSE){
$ idStarts = strpos($ formatted_url,“& v =”);
}
if(n if) $ idStarts!== FALSE){
//存在一个videoID,现在验证它
$ v = substr($ formatted_url,$ idStarts,$ idLength);
$ headers = get_headers('http:// gdata.youtube.com/feeds/api/videos/'。$ videoID);
//请求返回的http代码为2xx?
if(!strpos($ headers [0],'200')) {
$ isValid = true;
}
}
}
返回$ isValid;
code> pre>
div>
Why aren't your first two echo statements also echoing <span id="resultval">
?;
With the current markup and jQuery code this is why jQuery populates #special
with null
.
You need to change you PHP code to:
echo('<div id="special"><span id="resultval">The YouTube video does not exist.</span></div>');
echo('<div id="special"><span id="resultval">that is a valid youtube video</span></div>');
Although, I do not understand why you used such a roundabout way to populate #special
. You could have just started with a <p>
inside <div id="#special">
and then use the selector $("#special > p")
Good luck!