Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Handling <br> in RSS (PHP)

Handling <br> in RSS (PHP)
Thread Tools
Grizzled Veteran
Join Date: Jun 2001
Status: Offline
Reply With Quote
Aug 26, 2004, 05:19 AM
 
Alright, this one has me pulling my hair out...

I'm working on some PHP scripts to turn web pages into RSS feeds. I slice up all the data and get the item title, link, aritcle, and date out of them and parse them like they need to be. Now, the trouble is when I go to replace a few things with a <br> or <p>. When I do a str_replace() and the selected content gets replaced with a <br>, NetNewsWire tells me that the feed does not exist. It still does...the content just changled slightly. I believe it's trying to interpret the < and > as XML items and isn't telling me the right error message. (After all I can SEE the .rss file!) Alright..so I use &lt; and &gt; or htmlentities("<br>") instead. When I do that, the < and > symbols show up in the feed, which is also not what I want.

So my options are a) broken or b) angle brackets in my feed, both of which don't give me the simple new line in the feed description that I want. I see other feeds that use <br> and <p> in them, though...how are they doing it? Different encoding? Also...I run the page source through htmlspecialchars() before outputting it, and it makes <br>'s into &lt;br&gt;, and the symbols don't show up; it creates a new line like it should.

Why are my concatenated &lt; and &gt; (or < and >) any different than what htmlspecialchars() outputs for those symbols?
     
qyn
Dedicated MacNNer
Join Date: Dec 2000
Location: sj ca
Status: Offline
Reply With Quote
Aug 26, 2004, 08:27 AM
 
I don't think <br> is allowed in the RSS. If NetNewsWire interpreted the <*> as XML, it was right to do so. I presume you're using the RSS 1 spec (much simpler than the 2.0). If so, you might want to read the documentation at http://my.netscape.com/publish/forma...spec-0.91.html.
     
Mac Elite
Join Date: Sep 2000
Location: Tempe, AZ
Status: Offline
Reply With Quote
Aug 26, 2004, 10:24 AM
 
<br> isn't valid XML because there's no closing tag. Try <br/> instead.

You'll have the same issue with things like <img> and <input> tags.
Geekspiff - generating spiffdiddlee software since before you began paying attention.
     
Grizzled Veteran
Join Date: Jun 2001
Status: Offline
Reply With Quote
Aug 26, 2004, 12:29 PM
 
I tried <br /> (that's br-space-slash), and it had the same broken effect... it shouldn't even be interpreting what's inside the <description> tags as XML, should it? There's just HTML there, anyway.
     
qyn
Dedicated MacNNer
Join Date: Dec 2000
Location: sj ca
Status: Offline
Reply With Quote
Aug 27, 2004, 12:45 PM
 
Originally posted by macgyvr64:
I tried <br /> (that's br-space-slash), and it had the same broken effect... it shouldn't even be interpreting what's inside the <description> tags as XML, should it? There's just HTML there, anyway.
Actually, it should be interpreting what's inside the <description> tag, and no, it's not HTML. It's just plain text. Again, I refer you to the relevant section of the DTD, which states:

Code:
<!ELEMENT description (#PCDATA)>
where "PCDATA" means "parsed character data". So any reader that uses a validating parser will in fact parse what's inside a <description>.

I think the real solution is to not use <br> (or <br />), but "\n".
     
Grizzled Veteran
Join Date: Jun 2001
Status: Offline
Reply With Quote
Aug 27, 2004, 12:49 PM
 
Using \n puts a carriage return in the source if the XML, but it's ignored by NetNewsWire (the HTML I'm parsing is filled with \n's and none of them show up in the feed)
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 01:11 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2