XML提要上使用的get_file_contents返回的URL数据存在问题


Issue with URL data returned by get_file_contents used on XML feed

我正在使用file_get_contents()来检索xml提要数据,以便进行解析。然而,对于图像URL,我得到了我的基本URL作为图像URL的前缀,如下所示:-

http://server.com/http://server2.com/image.png

这是我的代码:

<? php
$context = stream_context_create(
array(
    'http' => array(
        'follow_location' => false
    )
)
);
$content =file_get_contents("http://xyogasangeetax.api.channel.livestream.com/2.0/latestclips.xml", false, $context);
$data = new SimpleXmlElement($content);
foreach($data->channel->item as $entry)
{
if ($media = $entry->children('media', TRUE)) {
$attributes = $media->content->attributes();
$src = $play_attributes['url'];
if ($media->thumbnail) {
$attributes = $media->thumbnail->attributes();
$imgsrc = (string)$attributes['url'];
echo "<img src='"'$imgsrc''" alt='"'" '/>";
}
}
$pub_date= explode("-",$entry->pubDate);
echo date('F d,Y',strtotime(trim($pub_date[0])));
}
?>  

请删除不需要的引号:

更改

echo "<img src='"'$imgsrc''" alt='"'" '/>";

echo "<img src='"$imgsrc'" alt='"'" '/>";