1

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

1 回答 1

0

请删除不需要的引号:

改变

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

echo "<img src=\"$imgsrc\" alt=\"\" \/>";
于 2013-07-23T22:49:36.747 回答