首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >正在检索带有标记<content:encoded>的RSS feed

正在检索带有标记<content:encoded>的RSS feed
EN

Stack Overflow用户
提问于 2010-07-28 02:21:00
回答 4查看 32.5K关注 0票数 26

我有以下代码片段:

代码语言:javascript
复制
function getFeed($feed_url) {

$content = file_get_contents($feed_url);
$x = new SimpleXmlElement($content);

echo "<ul>";

foreach($x->channel->item as $entry) {
    echo "<li><a href='$entry->link' title='$entry->title'>" . $entry->title . "</a></li>";
    echo "<li>$entry->content</li>";

echo "</ul>";
}

它可以正常工作,但$entry->content除外

这部分没有被记录下来。在实际的提要中,标签被列为<content:encoded>,但我无法将其作为提要。有什么建议吗?

EN

回答 4

Stack Overflow用户

发布于 2010-07-28 02:26:05

<content:encoded>中,contentnamespaceencoded是标记名。

您必须使用SimpleXMLElement::children。查看下面的输出

代码语言:javascript
复制
var_dump($entry->children("content", true));
票数 42
EN

Stack Overflow用户

发布于 2013-07-19 02:46:55

我建议您使用以下代码:

代码语言:javascript
复制
function getFeed($feed_url) {
        $feeds = file_get_contents($feed_url);
        $feeds = str_replace("<content:encoded>","<contentEncoded>",$feeds);
        $feeds = str_replace("</content:encoded>","</contentEncoded>",$feeds);
        $rss = simplexml_load_string($feeds);

    echo "<ul>";
        foreach($x->channel->item as $entry) {
        echo "<li><a href='$entry->link' title='$entry->title'>" . $entry->title . "</a></li>";
        echo "<li>$entry->contentEncoded</li>";

    echo "</ul>";
    }

希望这对你有用。

票数 11
EN

Stack Overflow用户

发布于 2015-10-20 17:58:12

……PHP示例

代码语言:javascript
复制
<?php 
// --------------------------------------------------------------------

$feed_url = 'http://www.tagesschau.de/xml/rss2'; 
$xml_data = simplexml_load_file($feed_url);

// -------------------------------------------------------------------- 

$i=0; 
foreach($xml_data->channel->item as $ritem) { 

// -------------------------------------- 

$e_title       = (string)$ritem->title; 
$e_link        = (string)$ritem->link; 
$e_pubDate     = (string)$ritem->pubDate; 
$e_description = (string)$ritem->description; 
$e_guid        = (string)$ritem->guid; 

$e_content     = $ritem->children("content", true);
$e_encoded     = (string)$e_content->encoded; 

$n = ($i+1);

// -------------------------------------- 

print '<p> ---------- '. $n .' ---------- </p>'."\n";

print "\n"; 
print '<div class="entry" style="margin:0 auto; padding:4px; text-align:left;">'."\n"; 
print '<p> Title: '. $e_title .'</p>'."\n"; 
print '<p> Link:  '. $e_link .'</p>'."\n"; 
print '<p> Date:  '. $e_pubDate .'</p>'."\n"; 
print '<p> Desc:  '. $e_description .'</p>'."\n"; 
print '<p> Guid:  '. $e_guid .'</p>'."\n"; 
print '<p> Content: </p>'."\n"; 
print '<p style="background:#DEDEDE">'. $e_encoded .'</p>'."\n"; 
print '</div>'."\n"; 


// -------------------------------------- 

print '<br />'."\n"; 
print '<br />'."\n";

$i++; 
} 

// -------------------------------------------------------------------- 
?>

如果您希望在浏览器中查看内容HTML源代码,请使用例如:

代码语言:javascript
复制
print '<pre style="background:#DEDEDE">'. htmlentities($e_encoded) .'</pre>'."\n";

:=)

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3346628

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档