Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Javascript Youtube API错误_Javascript_Php_Youtube Api - Fatal编程技术网

Php Javascript Youtube API错误

Php Javascript Youtube API错误,javascript,php,youtube-api,Javascript,Php,Youtube Api,我有以下代码,它在Html代码的一部分添加YouTube频道($\u POST)的视频(和视频信息): var args= "url="+urlchaine; xhr_object.open("POST", "traitement.php", true); xhr_object.onreadystatechange = function() { if(xhr_object.readyState == 4) { eval(xhr_object.re

我有以下代码,它在Html代码的一部分添加YouTube频道($\u POST)的视频(和视频信息):

    var args= "url="+urlchaine;
    xhr_object.open("POST", "traitement.php", true);
xhr_object.onreadystatechange = function() { 
    if(xhr_object.readyState == 4) {
            eval(xhr_object.responseText);
        }
        return xhr_object.readyState;
}
xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr_object.send(args);
traitement.php:

<?php
 if ( isset($_POST["url"]) && !empty($_POST["url"]) )
$urlchaine = $_POST["url"];
 else
$urlchaine = null;

 $stringresult = str_replace("http://www.youtube.com/user/", "",$urlchaine);

 require_once "Zend/Loader.php";
 Zend_Loader::loadClass('Zend_Gdata_YouTube');
 $yt = new Zend_Gdata_YouTube();
 //Get Video info with channel name $stringresult
 $videoFeed = $yt->getVideoFeed('http://gdata.youtube.com/feeds/users/...');

 if ( $stringresult != null){
  echo "var mydiv = document.getElementById('vids');";
  echo "var newcontent = document.createElement('div');";

  foreach ($videoFeed as $v): $thumbs = $v->getVideoThumbnails();
    $videoId = $v->getVideoId();
    $thumb = $thumbs[0]['url'];
    $videoViewCount = $v->getVideoViewCount();
    $videoTitle = $v->getVideoTitle();
echo "newcontent.innerHTML = 
 '<div class=\"videos\">' +
 ' <div class=\"img_videos\">' +
 '  <img class=\"img_video\" width=\"250\" idvideo=\"".$videoId."\" ' +
 '  src=\"".$thumb."\"/>' +
 ' </div>' +
 ' <h3>$videoTitle</h3>' +
 ' <p>$videoViewCount views</p>' +
 '</div>' ;";
echo "mydiv.appendChild(newcontent.firstChild);";
endforeach;
?>

$videoTitle
在某些情况下似乎包含一个简单的引用,这会破坏您的JS代码

尝试使用以下内容转义此引号:

str_replace("'", "&sbquo;", $videoTitle)