从youtube xml或json获取youtube标题


Get youtube title from youtube xml or json

我想从

获取YouTube视频标题
http://www.youtube.com/oembed?url=http://www.youtube.com/watch?v=dpe11FCFxBE&format=xml

在XML标题

<oembed>
<title>
TITLE IS HERE
</title>
</oembed>

所以我试着用这段代码来获取标题,但它不起作用

$json_output = file_get_contents("http://www.youtube.com/oembed?url=http://www.youtube.com/watch?v=".$video_id."&format=xml");
$fln = $json['oembed']['title'];

试试下面的代码…

$content = file_get_contents("http://www.youtube.com/oembed?url=http://www.youtube.com/watch?v=".$video_id."&format=json");
$json_output = json_decode($content, true);
$fln = $json_output['title'];

如果你想解析json输出,你应该使用format=json