gpt4 book ai didi

php - php代码无法正常工作

转载 作者:行者123 更新时间:2023-12-03 05:44:33 27 4
gpt4 key购买 nike

此代码有什么问题?

$feedURL = 'http://gdata.youtube.com/feeds/api/standardfeeds/US/most_viewed?v=2&time=all_time';
$site_url = 'http://localhost/';
// read feed into SimpleXML object
$sxml = simplexml_load_file($feedURL);
// iterate over entries in feed
foreach ($sxml->entry as $entry) {
// get nodes in media: namespace for media information
$media = $entry->children('http://search.yahoo.com/mrss/');
// get video player URL
$attrs = $media->group->player->attributes();
$watch = $attrs['url'];
$video_id = str_replace('http://www.youtube.com/watch?v=', '',$watch);
$video_id = str_replace('&feature=youtube_gdata', '',$video_id);
$video_id = str_replace('_player', '',$video_id);
echo $details .= '
'.$site_url.'video/'.$video_id.'';}

该代码应返回25个网址的列表(通过youtube api feed),格式为:

http://localhost/video/video-id/

但是代码返回并重复了一个丑陋的URL(我想要的格式)列表。

PS:在str_replace之前,链接已正确显示,但格式为:

http://www.youtube.com/watch?v=video-id&feature=youtube_gdata_player

怎么了?我该如何解决?

最佳答案

之前未定义echo $details .= '..'; $ details,因此请使用echo $details = '...'

关于php - php代码无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5363730/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com