Paragraph breaks in rss

I’ve recently started an rss feed for one of my sites but even after reading google search items and this forum I can’t make my feed show paragraph breaks. I’ve added an rss.css file which defines the different areas but of course that doesn’t define the “paragraphs”. I’ve included the xml:space=“preserve” tag in the description but that’s not doing the trick. Can I hard-code a <br> tag into the xml page? I don’t want to try it out in case it just displays the tag.

Any suggestions will be appreciated!

Paragraphs will show if you place CDATA code inside your <description> tags:

<description>
[COLOR="Red"]<![CDATA[ [/COLOR]

<p>paragraphs here</p>

[COLOR="Red"]]]>[/COLOR]
</description>

Give that a try and see if it works. That’s what I had to do to get paragraphs to show.

I did see the CDATA suggestion when I was searching but couldn’t figure out how it worked. Your post gave me the format and it works perfectly. Thanks ralph.m!

Great! Glad that solved it for you. :slight_smile:

I’m hoping you can see something I don’t in my code- just basic php building the xml file out of a mysql database, and the feed validates and shows up ok in IE8 and Chrome but without any paragraph breaks:

$output = "<?xml version=\“1.0\” encoding=\“utf-8\”?>
<rss version=\“2.0\”>
<channel>
<title>ZAZEN NOTES</title>
<link>http://www.zenmudra.com/zazen-notes/rss_php6.php&lt;/link&gt;
<description>ZAZEN NOTES</description>;

while ($row = mysql_fetch_array($result)) {
$output .=“<item>”;
$output .=“<title>”.htmlentities($row[‘post_title’]).“</title>”;
$output .=“<link>http://www.zenmudra.com/zazen-notes/index.php?post_id=“.htmlentities($row[‘post_id’]).”&lt;/link&gt;”;
$output .=“<guid>http://www.zenmudra.com/zazen-notes/index.php?post_id=“.htmlentities($row[‘post_id’]).”&lt;/guid&gt;”;
$output .=“<description>”.htmlentities($row[‘post_comment’],ENT_QUOTES,‘UTF-8’).“</description>”;
$output .=“</item>”;
}

$output .= “</channel></rss>”;

Thanks!- Mark

I should mention that I did try adding the CDATA tags to the item description and it made no difference. There’s no HTML in what’s coming out of the database, but there are linebreaks that show up on the blog itself; they don’t show when the rss feed is presented in IE8 or Chrome. Thanks for any advice you can offer…

Hi Mark, welcome to SitePoint. :slight_smile:

Have you tried something like

$output .="<description>[COLOR="Red"]<![CDATA[[/COLOR]".htmlentities($row['post_comment'],ENT_QUOTES,'UTF-8')."[COLOR="Red"]]]>[/COLOR]</description>";

(You might need to escape a few of those characters, like [. I’m not very experienced with PHP.)

Ralph, thanks very much for your reply- yes, that’s where I put the CDATA tags, exactly- made no difference, though.

On my blog site, there are breaks between the paragraphs, but since there are no html tags, I assume the browser is recognizing line breaks which are not html. I admit, I’m hazy on this! I wonder if the use of “ENT_QUOTES, ‘UTF-8’” in connection with htmlentities is somehow removing those line breaks, but my feed doesn’t work without that. I think it must be connected, previously I replaced quotes with blanks in a parsing algorhythm and then put them back in manually in the database- I think I’ve only had this problem since I took quotes out of my parsing algorhythm.

[QUOTE=Mark Foote;4839958]Ralph, thanks very much for your reply- yes, that’s where I put the CDATA tags, exactly- made no difference, though.
[/QUOTiE]

More- I took out htmlentities completely, added the CDATA tags back in on the inside of the description tags, and the rss feed validates and displays links where I have them in the blog which is good. Doesn’t do line breaks, though, just one big paragraph!

Ok, now I have borrowed a function I found on the documentation for the PHP nl2br() function, it’s here: PHP: nl2br - Manual, thanks to fort hub dot com- so my code I’m adding is:

$temp_hold_description = “”;
function NlToBr($inString)
{
return preg_replace(“%
%”, “<br />”, $inString);
}

and now the “while” loop looks as below, this has given me line breaks when I pull up the rss feed in IE8, but still not in the Google Reader- (I’m hopeful that maybe in a few hours, although clearing my local browser cache on Chrome did nothing):

while ($row = mysql_fetch_array($result)) {
$output .=“<item>”;
$output .=“<title>”.htmlentities($row[‘post_title’]).“</title>”;
$output .=“<link>http://www.zenmudra.com/zazen-notes/index.php?post_id=“.htmlentities($row[‘post_id’]).”&lt;/link&gt;”;
$temp_hold_description = NlToBr($row[‘post_comment’]);
$output .=“<description><![CDATA[”.$temp_hold_description.“]]></description>”;
$output .=“</item>”;
}

Thanks again, ralph.m, for giving me the second set of eyes boost, and wish me luck.

quick note to say that I didn’t think my host’s PHP4 would do nl2br() function, but it’s ok for PHP4, so I could have used that above (as someone else advised, somewhere?). Getting line breaks in Chrome now as well, happy day.

That sounds odd. Why no HTML markup? There must be something in there for the browser to recognize para breaks.

I have a little piece of feed display code, and when I looked at the source code of my feed display I could see that there were paragraph tags at the start and close of each item description, and that was it. There were line breaks, however, in the display on my blog.

Since I was able to use a function that replaced
with <br /> and get the spacing in the feed, I conclude that was the issue. Why no one else seems to have a problem after they put CDATA tags around the description, I don’t know!

Thanks again for being there, it helped me think more objectively to feel someone else was looking at it with me. Have a great day!