如何在RSS feed中添加换行符? [英] How to add line breaks in RSS feeds?

查看:101
本文介绍了如何在RSS feed中添加换行符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用PHP构建自己的自定义RSS feed.我希望标签包含换行符以使文本更易读.但是,我似乎无法弄清楚如何正确地做到这一点.不管我尝试什么,一些RSS阅读器都会错误地解释它.是否有一些标准的最佳方法来添加换行符和RSS 2.0 feed?

I'm building my own custom RSS feed in PHP. I want the tag to contain line breaks to make the text more readable. However, I can't seem to figure out how to do it correctly. No matter what I try some RSS reader interprets it incorrectly. Is there some standard best way to add a line-break in and RSS 2.0 feed?

我尝试过"\ n",它可以在Mac上的NetNewsWire中使用,但是会被内置的Safari浏览器的RSS阅读器忽略.

I have tried "\n", which works in NetNewsWire on the Mac, but gets ignored by the built-in Safari browser's RSS reader.

我已经尝试过< br/> ;,它可以在Safari RSS阅读器中使用,但是导致
之后的所有文本在NetNewsWire中被剪掉.

I have tried <br />, which works in the Safari RSS reader, but results in all the text after the
being cut off in NetNewsWire.

推荐答案

默认情况下,除非您告诉读者,否则读者将尝试解析您的数据.要让他们跳过它并按预期显示它,您必须在其中声明一个CDATA部分RSS .

By default, readers will try and parse your data unless you tell them not to. To have them skip over it and present it as you intend, you have to declare a CDATA section in the RSS.

如果原始数据已经包含换行符,那么您也应该能够使用nl2br()函数像这样添加<br />:

If the raw data already has newlines, then you should also be able to just use the nl2br() function to add in the <br /> like so:

echo '<description><![CDATA[ ' .nl2br($desc_data). ' ]]></description>';

如果不声明CDATA部分,则RSS阅读器将看到您可能在实际RSS中包含的所有HTML标签,并期望RSS提要的实际节点或元素.

If you don't declare the CDATA section, the RSS readers will see any HTML tags you might have as part of the actual RSS and expect an actual node or element of the RSS feed.

这篇关于如何在RSS feed中添加换行符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆