通过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;

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!