【问题标题】:My Function Breaks Site我的功能中断站点
【发布时间】:2014-09-02 19:20:42
【问题描述】:
<?php
if (isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING'])) { 
$id = $_SERVER['QUERY_STRING'];
$url = 'http://www.youtube.com/watch?v='.$id;

function get_youtube($url) {    
    $youtube = "http://www.youtube.com/oembed?url=" .$url. "&format=json";
    $json =  file_get_contents($youtube);
    return json_decode($json);
}

$json = get_youtube($url);

$thumb = $json->thumbnail_url;
$title = $json->title;
$artist = $json->author_name;
$thumb = $json->thumbnail_url;
$keywords = implode(", ", preg_split("/[\s]+/", $title));

echo '<title>MUZZIL | '.$title.'</title>';
echo '<meta name="description" content="Listen, watch &amp; download to '.$title.' by '.$artist.' on MUZZIL. Work easy, play easy. The perfect music tool for parties or casual listening.">';
echo '<meta name="keywords" content="'.$keywords.', '.$artist.', mp3, stream, official, lyrics, watch, free, music, song, playlist, youtube, download, listen, videos, MUZZIL, muzill">';
echo '<meta name="thumbnail" content="'.$thumb.'" />';

} else {
echo '<title>MUZZIL | Work Easy, Play Easy</title>';
echo '<meta name="description" content="Work easy, play easy. Listen, download and watch music free with auto playlist. The perfect music tool for parties or casual listening.">';
echo '<meta name="keywords" content="mp3, stream, official, lyrics, watch, free, music, song, playlist, youtube, download, listen, videos, MUZZIL, muzill">';
echo '<meta name="thumbnail" content="http://muzzil.com/img/lm.png" />';
}
?>

当我没有参数时,代码可以正常工作,但如果有 URL 参数则会中断。我已经设法将问题定位到 get_youtube() 但我找不到确切的原因。也没有生成错误日志。

提前致谢。

【问题讨论】:

  • 回显$id。你会注意到它会说id=mycode,而不仅仅是mycode。您可以使用$_GETQUERY_STRING 中检索特定值。

标签: php json youtube-data-api


【解决方案1】:

试试我的网址是 = http://example.com/clone.php?5O86FUOrlkY 检查empty() 响应并返回

<?php
if (isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING'])) { 
echo $id = $_SERVER['QUERY_STRING'];
$url = 'http://www.youtube.com/watch?v='.$id;

function get_youtube($url) {    
    $youtube = "http://www.youtube.com/oembed?url=" .$url. "&format=json";
    $json =  @file_get_contents($youtube);
    if(empty($json)) {
      return 'NO VIDEO FOUND';
     }  
    return json_decode($json, true);
}

$json = get_youtube($url);
print_r($json);
echo $thumb = $json['thumbnail_url']; //http://i1.ytimg.com/vi/5O86FUOrlkY/hqdefault.jpg
echo $title = $json['title']; //Finding Fanny | Official Trailer | Arjun Kapoor, Deepika 
echo $artist = $json['author_name']; //PadukoneFoxStarHindi
echo $thumb = $json['thumbnail_url'];
echo $keywords = implode(", ", preg_split("/[\s]+/", $title));

echo '<title>MUZZIL | '.$title.'</title>';
echo '<meta name="description" content="Listen, watch &amp; download to '.$title.' by '.$artist.' on MUZZIL. Work easy, play easy. The perfect music tool for parties or casual listening.">';
echo '<meta name="keywords" content="'.$keywords.', '.$artist.', mp3, stream, official, lyrics, watch, free, music, song, playlist, youtube, download, listen, videos, MUZZIL, muzill">';
echo '<meta name="thumbnail" content="'.$thumb.'" />';

} else {
echo '<title>MUZZIL | Work Easy, Play Easy</title>';
echo '<meta name="description" content="Work easy, play easy. Listen, download and watch music free with auto playlist. The perfect music tool for parties or casual listening.">';
echo '<meta name="keywords" content="mp3, stream, official, lyrics, watch, free, music, song, playlist, youtube, download, listen, videos, MUZZIL, muzill">';
echo '<meta name="thumbnail" content="http://muzzil.com/img/lm.png" />';
}
?>

【讨论】:

  • 感谢帮助,原来是函数名冲突。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-04-01
  • 2015-01-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多