RSS 提要和 cdata 的问题 [英] problem with rss feed and cdata
问题描述
我的 rss 提要有问题.
I have a problem with an rss feed.
当我做
标题在提要中显示得很好
The title appears nicely in the feed
但是当我这样做的时候$title = "这是一个倾斜";
But when i ddo $title = "this is a tilte";
<title><![CDATA['$title']]></title>
标题根本没有出现.
还是不行.我动态生成我的 RSS 提要,它看起来像这样:
It still doesn't work. I generate my rss feed dynamicly and it looks like this:
$item_template="
<item>
<title>[[title]]</title>
<link>[[link]]</link>
<description><![CDATA[[[description]]]]></description>
<pubDate>[[date]]</pubDate>
</item>
";
并在循环中:
$s.=str_replace(
array("[[title]]","[[link]]","[[description]]","[[date]]"),
array(htmlentities($row["title"]),$url,$description,$date),
$item_template);
问题特别在于标题有欧元符号时.然后它显示在我的 rss 验证器中,例如:
The problem is specifically when the title has a euro sign. Then it shows up in my rss validator like:
Â\x80
<小时>
更多详细信息:
好的,过去几天我一直在为此苦苦挣扎,但找不到解决方案.所以我将开始赏金.以下是更多信息:
Ok I have been struggeling with this for the last few days and I can't find a solution. So I will start a bounty. Here is more information:
- Feed 中的信息存储在 latin 1 数据库中(我管理)
- 当数据库中有欧元符号时就会出现问题.无论是 € 还是
€
- 欧元符号有时看起来像奇怪的字符或像 \x80
- 我尝试在提要方面解决问题,而不是在读者方面.
- 完整代码可以在这里找到:codedump
- 下一步:有时当欧元符号无法解析时,项目(标题或描述)显示为空.因此,如果您在浏览器中显示提要时查看源代码,您会发现
<title></title>
如果需要更多信息,请询问.
If there is more information needed please ask.
推荐答案
问题是你输出的代码;改变
The problem is your outputting code; change
echo '<title><![CDATA[$title]]></title>';
到
echo '<title><![CDATA[' . $title . ']]></title>';
作为旁注,请注意以下事项:不要用后续问题回答您自己的问题,而是编辑原始问题.不要无缘无故地使用正则表达式.不要猜测.
As a side note, please mind the following: Do not answer your own question with a follow-up, but edit the original one. Do not use regexps for no good reason. Do not guess.
相反,做你一直以来应该做的事情:将标题包裹在 htmlentitites
并完成,如:
Instead, do what you should have done all along: Wrap the title in htmlentitites
and be done, as in:
echo '<title>' . htmlentities($title, ENT_NOQUOTES, [encoding]) . '</title>';
将 [encoding]
替换为您正在使用的字符编码.最有可能的是UTF-8".这是必要的,因为 php(<6) 默认使用 ISO-8859-1 并且没有办法表达例如该编码中的欧元符号.如需更多信息,请参阅此精心编写的介绍.
Replace [encoding]
with the character encoding you are using. Most likely, this is 'UTF-8'. This is necessary because php(<6) uses ISO-8859-1 by default and there is no way to express e.g. the Euro sign in that encoding. For further information, please refer to this well-written introduction.
我还建议您阅读有关 XML 的内容.从第二章开始.
I also suggest you read about XML. Start with the second chapter.
这篇关于RSS 提要和 cdata 的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!