【发布时间】: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 & 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。您可以使用$_GET从QUERY_STRING中检索特定值。
标签: php json youtube-data-api