SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2009
    Location
    British Columbia, Canada
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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!

  2. #2
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,301
    Mentioned
    460 Post(s)
    Tagged
    8 Thread(s)
    Paragraphs will show if you place CDATA code inside your <description> tags:

    Code:
    <description>
    <![CDATA[  
    
    <p>paragraphs here</p>  
    
    ]]>
    </description>
    Give that a try and see if it works. That's what I had to do to get paragraphs to show.

  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2009
    Location
    British Columbia, Canada
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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!

  4. #4
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,301
    Mentioned
    460 Post(s)
    Tagged
    8 Thread(s)
    Great! Glad that solved it for you.

  5. #5
    SitePoint Member
    Join Date
    Mar 2011
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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</link>
    <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'])."</link>";
    $output .="<guid>http://www.zenmudra.com/zazen-notes/index.php?post_id=".htmlentities($row['post_id'])."</guid>";
    $output .="<description>".htmlentities($row['post_comment'],ENT_QUOTES,'UTF-8')."</description>";
    $output .="</item>";
    }

    $output .= "</channel></rss>";


    Thanks!- Mark

  6. #6
    SitePoint Member
    Join Date
    Mar 2011
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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...

  7. #7
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,301
    Mentioned
    460 Post(s)
    Tagged
    8 Thread(s)
    Hi Mark, welcome to SitePoint.

    Have you tried something like

    Code:
    $output .="<description><![CDATA[".htmlentities($row['post_comment'],ENT_QUOTES,'UTF-8')."]]></description>";
    (You might need to escape a few of those characters, like [. I'm not very experienced with PHP.)

  8. #8
    SitePoint Member
    Join Date
    Mar 2011
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ralph.m View Post
    Hi Mark, welcome to SitePoint.

    Have you tried something like

    Code:
    $output .="<description><![CDATA[".htmlentities($row['post_comment'],ENT_QUOTES,'UTF-8')."]]></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.

  9. #9
    SitePoint Member
    Join Date
    Mar 2011
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    [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("%\n%", "<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'])."</link>";
    $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.

  10. #10
    SitePoint Member
    Join Date
    Mar 2011
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  11. #11
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,301
    Mentioned
    460 Post(s)
    Tagged
    8 Thread(s)
    Quote Originally Posted by Mark Foote View Post
    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.
    That sounds odd. Why no HTML markup? There must be something in there for the browser to recognize para breaks.

  12. #12
    SitePoint Member
    Join Date
    Mar 2011
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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 \n 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!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •