0
我有以下代碼:獲取YouTube數據API的縮略圖用SimpleXML
$rss = simplexml_load_file('http://gdata.youtube.com/feeds/api/playlists/PLEA1736AA2720470C?v=2&prettyprint=true');
foreach ($rss->entry as $entry) {
// get nodes in media: namespace for media information
$media = $entry->children('http://search.yahoo.com/mrss/');
$thumbs = $media->group->thumbnail;
$thumb_attrs = array();
$index = 0;
// get thumbnails attributes: url | height | width
foreach ($thumbs as $thumb) {
foreach ($thumb->attributes() as $attr => $value) {
$thumb_attrs[$index][$attr] = $value;
print $attr . ': ' . $thumb_attrs[$index][$attr] . "| ";
}
$index++;
print "<br>";
}
}
則打印輸出:
url: http://i.ytimg.com/vi/te28_L-dO88/default.jpg| height: 90| width: 120| time: 00:00:49|
...
從以下格式的XML標籤:
<media:thumbnail url='http://i.ytimg.com/vi/4l4rwvAPhfA/default.jpg' height='90' width='120' time='00:02:23.500' yt:name='default'/>
...
如何添加名稱空間yt name ='default'的屬性,我沒有進入數組?
我怎樣才能得到最接近的所有寬度值與數組中的其他值?類似於PHP - Nearest value from an array,但考慮到我的數組是多維的。