使用Youtube頻道如何解析$ link變量並獲取視頻ID?我能得到的鏈接,但parse_str部分似乎並不正常工作YouTube從鏈接解析視頻ID
YouTube的ID解析:試圖讓下面
if (! empty($xml->channel->item[0]->link))
{
parse_str(parse_url($xml->channel->item[0]->link, PHP_URL_QUERY), $url_query);
if (! empty($url_query['v']))
$id = $url_query['v'];
}
echo $id;
當前的代碼以目前的代碼工作:
<?php
$id = NULL;
$username = 'utahblaze';
$url = 'http://gdata.youtube.com/feeds/api/users/%s/uploads?orderby=updated&max-results=8';
$xml = simplexml_load_file(sprintf($url, $username));
foreach ($xml->entry as $entry) :
$kids = $entry->children('http://search.yahoo.com/mrss/');
$attributes = $kids->group->content[0]->attributes();
$flv = $attributes['url'];
$attributes = $kids->group->player->attributes();
$link = $attributes['url'];
echo $id;
echo $link;
?>
<a id="ytopen" href="<?=$link?>">
<img src="http://i4.ytimg.com/vi/<?=$id?>/default.jpg" /></a>
<?php endforeach; ?>
+1不使用正則表達式來解析PHP中的URL。 – 2012-02-16 20:28:19