【发布时间】:2019-07-27 18:12:57
【问题描述】:
考虑以下 XML 结构(在这种情况下,它是一个 RSS 提要)
<feed xmlns="http://www.w3.org/2005/Atom">
<link href="http://example.com/atom/" rel="self" type="application/rss+xml"/>
<link rel="alternate" href="http://example.com/" type="text/html"/>
<title type="text">Example RSS feed</title>
<updated>2019-07-27T13:59:14-04:00</updated>
<subtitle>Example</subtitle>
<icon>http://example.com/favicon-32x32.png</icon>
<logo>http://example.com/logo.png</logo>
<rights>© 2019 Example</rights>
<author>
<name>Keanu Reeves</name>
<email>me@example.com</email>
<uri>http://example.com</uri>
</author>
<id>http://example.com/</id>
<entry>
<title>Example post</title>
<id>http://example.com/post/example</id>
<link rel="alternate" href="http://example.com/post/example"/>
<summary type="html">
Description of post. (Preview thing)
</summary>
<updated>2019-07-27T13:59:14-04:00</updated>
<author>
<name>Keanu Reeves</name>
</author>
</entry>
</feed>
如果保存为 .atom 文件,则可以完美运行。
尽管如此,我想在我的帖子summary 中包含以下内容:
Example text, blah blah blah. <a href="/post/example">Read more...</a>
The above links get interpreted as litteral HTML when escaped correctly using the function under this code snippet. Good!
Now, heres litteral "<" and ">" characters.... <><><<<>>
我想包含的最后一行显然会使 .atom 文件无效。因此,我使用以下 PHP 函数将最后一行编码为符合 XML 标准:
echo htmlentities("Now, heres litteral \"<\" and \">\" characters.... <><><<<>>",ENT_XML1);
输出如下文本:
Now, heres litteral "<" and ">" characters.... <><><<<>>
但现在,我所有的提要阅读器(Chrome 的 Slick RSS 和 android 的 FeedR)都将上述内容解释为文字 HTML!
那么我怎样才能重新逃脱那些呢?
干杯:)
【问题讨论】:
标签: php html xml rss atom-feed