我正在使用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])));
}
?>