Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/275.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 从youtube api输出中删除videoid_Php_Youtube Api - Fatal编程技术网

Php 从youtube api输出中删除videoid

Php 从youtube api输出中删除videoid,php,youtube-api,Php,Youtube Api,我正在使用youtube api搜索视频。我的问题是,当搜索完成时,搜索的输出是 video_name video_id 我只是想让它表现出来 video_name 这是我显示搜索结果的代码 $client = new Google_Client(); $client->setDeveloperKey($DEVELOPER_KEY); $youtube = new Google_Service_YouTube($client); try { $searchResponse

我正在使用youtube api搜索视频。我的问题是,当搜索完成时,搜索的输出是

video_name  video_id
我只是想让它表现出来

video_name
这是我显示搜索结果的代码

 $client = new Google_Client();
$client->setDeveloperKey($DEVELOPER_KEY);


$youtube = new Google_Service_YouTube($client);

try {

$searchResponse = $youtube->search->listSearch('id,snippet', array(
  'q' => $_GET['q'],
  'maxResults' => $_GET['maxResults'],
));

$videos = '';
$channels = '';
$playlists = '';

// Add each result to the appropriate list, and then display the lists of
// matching videos, channels, and playlists.
foreach ($searchResponse['items'] as $searchResult) {
 $imgsrc="<img src=http://img.youtube.com/vi/".$searchResult['id']
               ['videoId']."/hqdefault.jpg height=125 width=125>";
  switch ($searchResult['id']['kind']) {  
    case 'youtube#video':  
      $videos .= sprintf('<li>'.$imgsrc.' %s (%s)</li>', $searchResult['snippet']['title'],  
        $searchResult['id']['videoId']."<a href=/video.php?".$searchResult['id']['videoId']." target=_blank>   Watch This Video</a>");  
      break;  
$client=new Google_client();
$client->setDeveloperKey($DEVELOPER\u KEY);
$youtube=新的谷歌服务\ youtube($client);
试一试{
$searchResponse=$youtube->search->listSearch('id,snippet',数组(
'q'=>$\u GET['q'],
'maxResults'=>$\u GET['maxResults'],
));
$videos='';
$channels='';
$playlists='';
//将每个结果添加到相应的列表中,然后显示结果列表
//匹配视频、频道和播放列表。
foreach($searchResponse['items']作为$searchResult){
$imgsrc=“”;
开关($searchResult['id']['kind']){
“youtube视频”案例:
$videos.=sprintf(“
  • ”。$imgsrc.%s(%s)
  • ”,$searchResult['snippet']['title'], $searchResult['id']['videoId']。“”); 打破
    我不太熟悉
    sprintf
    ,但您想删除它

    $searchResult['id']['videoId']

    不破坏你的代码

    我建议用一根特殊的绳子把它包起来

    vidid[“$searchResult['id']['videoId']”]


    然后删除
    vidid[
    ]

    之间的所有内容。能否显示实际输出的示例?迈克尔·杰克逊-镜中人(原始剪辑)(F9Nh84lfvW0观看此视频),我希望输出为迈克尔·杰克逊-镜中人(原始剪辑)(观看此视频)我不太熟悉
    sprintf
    ,但您希望在不破坏代码的情况下删除
    $searchResult['id']['videoId']
    。我建议将其包装在特定字符串之间,例如
    vidid[“$searchResult['id']['videoId']”。]
    ,然后删除
    vidid[
    之间的所有内容
    。不过,这可能不是最好的解决方法:太完美了!工作非常有魅力!将其作为答案提交,这样我就可以为你选择答案了甜心,很高兴我能帮上忙=)