Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add line breaks in RSS feeds?

Tags:

php

xml

rss

feed

rss2

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?

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

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

like image 315
Candidasa Avatar asked Aug 29 '09 10:08

Candidasa


People also ask

How do I add a new line in XML?

You can use &#xA; for line feed (LF) or &#xD; for carriage return (CR), and an XML parser will replace it with the respective character when handing off the parsed text to an application.

How does XML store the new line character in Macintosh application?

XML Stores New Line as LF Windows applications store a new line as: carriage return and line feed (CR+LF). Unix and Mac OSX use LF.

What is RSS feed in android?

Android App Development for Beginners RSS stands for Really Simple Syndication. RSS is an easy way to share your website updates and content with your users so that users might not have to visit your site daily for any kind of updates.


2 Answers

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.

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>';

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.

like image 84
random Avatar answered Nov 06 '22 15:11

random


You can use CDATA and html line breaks: <br/>
Example:

<![CDATA[Hi Rss feed<br/>
Here is new line ]]>

like image 42
Vitaly Dyatlov Avatar answered Nov 06 '22 17:11

Vitaly Dyatlov