How to add line breaks in RSS feeds?

后端 未结 4 1567
灰色年华
灰色年华 2020-12-17 02:03

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 correct

相关标签:
4条回答
  • file_put_contents("rss.txt","<br>") roach idea
    
    0 讨论(0)
  • 2020-12-17 02:28

    The RSS specification states that yes, you can use HTML in a description, but of course it needs to be properly escaped because it is embedded in XML. So using a <br> is the right idea, but you need to encode it using either of these methods, take your pick:

    <description>first line&lt;br&gt;second line</description>
    
    <description><![CDATA[first line<br>second line]]></description>
    
    0 讨论(0)
  • 2020-12-17 02:38

    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.

    0 讨论(0)
  • 2020-12-17 02:40

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

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

    0 讨论(0)
提交回复
热议问题