gpt4 book ai didi

coldfusion - 如何删除 RSS 源中的奇怪字符?

转载 作者:行者123 更新时间:2023-12-02 06:42:17 24 4
gpt4 key购买 nike

我创建了一个 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>

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

提前致谢,

克罗米斯

最佳答案

摆脱转义代码并使用 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.

关于coldfusion - 如何删除 RSS 源中的奇怪字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/362429/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com