【问题标题】:How to get rid of weird characters in my RSS feed?如何摆脱我的 RSS 提要中的奇怪字符?
【发布时间】:2008-12-12 10:36:14
【问题描述】:

我创建了一个 utf8 编码的 RSS 提要,它显示了从数据库中提取的新闻数据。我已将数据库的所有方面都设置为 utf8,并将我放入数据库的文本保存为 utf8,方法是将其粘贴到记事本中并另存为 utf8。因此,当 RSS 提要呈现给浏览器时,所有内容都应该以 utf8 编码,但是我仍然会收到奇怪的问号字符:(

这是我的 RSS 提要代码 (CFML):

<cfsilent>
<!--- Get News --->
<cfinvoke component="com.news" method="getAll" dsn="#Request.App.dsn#"     returnvariable="news" />
</cfsilent>
<!--- If we have news items --->
cfif news.RecordCount GT 0>
<!--- Serve RSS content-type --->
<cfcontent type="application/rss+xml">
<!--- Output feed --->
<cfcontent reset="true"><?xml version="1.0" encoding="utf-8"?>
<cfoutput>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
        <title>News RSS Feed</title>
        <link>#Application.siteRoot#</link>
        <description>Welcome to the News RSS Feed</description>
        <lastBuildDate>Wed, 19 Nov 2008 09:05:00 GMT</lastBuildDate>
        <language>en-uk</language>
        <atom:link href="#Application.siteRoot#news/rss/index.cfm" rel="self" type="application/rss+xml" />

    <cfloop query="news">
    <!--- Make data xml compliant --->
        <cfscript>
        news.headline = replace(news.headline, "<", "&lt;", "ALL");
        news.body = replace(news.body, "<", "&lt;", "ALL");
        news.date = dateformat(news.date, "ddd, dd mmm yyyy");
        news.time = timeformat(news.time, "HH:mm:ss") & " GMT"; 
        </cfscript>        
    <item>
        <title>#news.headline#</title>
        <link>#Application.siteRoot#news/index.cfm?id=#news.id#</link>
        <guid>#Application.siteRoot#news/index.cfm?id=#news.id#</guid>
        <pubDate>#news.date# #news.time#</pubDate>
        <description>#news.body#</description>
    </item>
    </cfloop>
    </channel>
</rss>
</cfoutput>
<cfelse>
<!--- If we have no news items, relocate to news page --->
<cflocation url="../news/index.cfm" addtoken="no">
</cfif> 

有人有什么建议吗?我做了很多研究,但找不到任何答案:(

提前致谢,

克罗米斯

【问题讨论】:

    标签: coldfusion utf-8 rss character-encoding


    【解决方案1】:

    摆脱转义代码并改用 XMLFormat:

    <item>
        <title>#XMLFormat(news.headline)#</title>
        <link>#Application.siteRoot#news/index.cfm?id=#XMLFormat(news.id)#</link>
        <guid>#Application.siteRoot#news/index.cfm?id=#XMLFormat(news.id)#</guid>
        <pubDate>#XMLFormat(news.date)# #XMLFormat(news.time)#</pubDate>
        <description>#XMLFormat(news.body)#</description>
    </item>
    

    View XMLFormat livedoc page.

    【讨论】:

      【解决方案2】:

      这对我有用,只需合并成一个 cfcontent 标签并附加 charset=utf-8。 &lt;cfcontent type="text/xml; charset=utf-8" reset="yes" /&gt;

      【讨论】:

        【解决方案3】:

        你的转义函数太简单了。您需要先将&amp;amp; 更改为&amp;amp;

        如果您使用命名实体(即&amp;pound;),则会导致错误。

        【讨论】:

          【解决方案4】:

          在输入数据库时​​对每个输入进行清理,这样可以简化之后此类数据的显示。

          【讨论】:

            【解决方案5】:

            如果您使用的是 Adob​​e ColdFusion 9 或更高版本,请考虑使用带有“escapeChars”属性的 CFFEED 来创建您的 RSS(CF8 也支持 CFFEED,但不支持该属性)。

            http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7675.html

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 2016-01-03
              • 1970-01-01
              • 2015-10-31
              • 2019-06-03
              • 1970-01-01
              • 1970-01-01
              • 2021-01-20
              • 1970-01-01
              相关资源
              最近更新 更多