codeigniter中的RSS提要,无法在标签中运行{php}

时间:2022-08-03 04:55:08

I have create an rss feed, all things is going to work well, but in this xml code

我已经创建了一个rss feed,所有东西都能很好地工作,但是在这个xml代码中

<description><![CDATA[****no php is allowed here****]]></description>

here is my view that generate the xml file

这是我生成xml文件的视图

<?php 
echo '<?xml version="1.0" encoding="utf-8"?>' . "\n";
?>
<rss version="2.0"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
    xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
    xmlns:admin="http://webns.net/mvcb/"
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:content="http://purl.org/rss/1.0/modules/content/">

    <channel>

    <title><?php echo $feed_name; ?></title>

    <link><?php echo $feed_url; ?></link>
    <description><?php echo $page_description; ?></description>
    <dc:language><?php echo $page_language; ?></dc:language>
    <dc:creator><?php echo $creator_email; ?></dc:creator>

    <dc:rights>Copyright <?php echo gmdate("Y", time()); ?></dc:rights>
    <admin:generatorAgent rdf:resource="http://www.codeigniter.com/" />

    <?php foreach($posts as $entry): ?>

        <item>

          <title><?php echo $entry->title_nw; ?></title>
          <link><?php echo site_url('view=entry'.'&amp;'.'id=' . $entry->id_nw); ?></link>
          <guid><?php echo site_url('blog/post/' . $entry->url_title); ?></guid>

          <description><![CDATA[
      <?php character_limiter($entry->text_nw, 200); ?>
      ]]></description>
      <pubDate><?php echo $entry->date_nw;?></pubDate>
        </item>


    <?php endforeach; ?>

    </channel></rss>

please scroll down and you can see this code

请向下滚动,您可以看到此代码

      <description><![CDATA[
  <?php character_limiter($entry->text_nw, 200); ?>
  ]]></description>

here is the problem that this code is not acceptable in the description tag

这是代码在description标记中不可接受的问题

1 个解决方案

#1


1  

IIRC character_limiter() doesn't echo results, just returns them. So:

IIRC character_limiter()不回显结果,只返回它们。所以:

1) make sure you've loaded the text helper in your controller before calling that function
2) try with:

1)确保在调用该函数之前已在控制器中加载了文本助手2)尝试使用:

<description><?php echo htmlspecialchars(character_limiter($entry->text_nw, 200)); ?></description>

#1


1  

IIRC character_limiter() doesn't echo results, just returns them. So:

IIRC character_limiter()不回显结果,只返回它们。所以:

1) make sure you've loaded the text helper in your controller before calling that function
2) try with:

1)确保在调用该函数之前已在控制器中加载了文本助手2)尝试使用:

<description><?php echo htmlspecialchars(character_limiter($entry->text_nw, 200)); ?></description>