Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Parsing RSS - removing line breaks
Old 12-03-2008, 12:24 PM Parsing RSS - removing line breaks
Y-aji's Avatar
Skilled Talker

Posts: 53
Name: Keith
Trades: 0
Hello all,

I am working on trying to receive an RSS feed and insert it into a scrolling box for students to read their local news, I get everything and it works fine, except that the RSS feed puts some kind of weird server side line breaks into it. I was curious if anyone knew how to remove any unconventional line breaks from a feed that is ASP driven (i.e. \r, \n, etc). When it comes in, there are mysterious carraige returns all over the place that I can't seem to remove, and my js feed rotator needs everything to be in one line, so page breaks breaks the javascript. I am currently running the following commands on it and these do not fix this particular page break:

php addslashes(trim(strip_tags($this->title)))

Any thoughts or ideas would be wonderful. I googled asp page breaks and didn't see anything obvious. As always, thank you. I have wasted like 50 hours of my life trying to fix these little errors.
Y-aji is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 12-03-2008, 01:14 PM Re: Parsing RSS - removing line breaks
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
str_replace("\r\n","",$this->title)
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 12-03-2008, 02:00 PM Re: Parsing RSS - removing line breaks
Y-aji's Avatar
Skilled Talker

Posts: 53
Name: Keith
Trades: 0
Unfortunately that doesn't work. Trim already yanks out \r & \n. I have tried everything conventional. I've gone as far as trying things like
str_replace("chr(13)","",$this->title). The following is an idea of basically what it is doing (i put in the double spaces everywhere it puts a fresh line)
Code:
        fcontent[0]='<b><a alt="http://www.ourwebsite.com/podium/default.aspx?t=204&id=9ohiVgu8jcc%3d">Happy Birthday!</a></b><br />Dec 2  firstname lastname, firstname lastname

Dec 3 firstname lastname

Dec 7  firstname lastname, firstname lastname, firstname lastname,  firstname lastname'

        closetag='</div>';
It is supposed to look like:
Code:
        fcontent[0]='<b><a alt="http://www.ourwebsite.org/podium/default.aspx?t=204&id=9ohiVgu8jcc%3d">Happy Birthday!</a></b><br />Dec 2 firstname lastname, firstname lastname Dec 3 firstname lastname Dec 7 firstname lastname, firstname lastname, firstname lastname, firstname lastname'
        closetag='</div>';
The person running this rss feed is putting <ul>'s & <li>'s around each date. Which I remove with strip_tags(), but trim doesn't get rid of the carraige returns. It does remove them in all other feeds.

I can remove the carraige returns from a normal RSS feed.

Last edited by Y-aji; 12-03-2008 at 02:02 PM.. Reason: Privacy again (sorry)
Y-aji is offline
Reply With Quote
View Public Profile
 
Old 12-03-2008, 04:14 PM Re: Parsing RSS - removing line breaks
Insensus's Avatar
Ultra Talker

Posts: 487
Name: Mark Stegeman
Location: Netherlands, Europe
Trades: 0
I think you need to re-read what the trim function actually does.
http://php.net/manual/en/function.trim.php
It doesn't strip all CR's and LF's, only those at the beginning and end of the supplied string.
__________________
<?php ($helpfull>0)?$talkupation++ : '';?>
Insensus is offline
Reply With Quote
View Public Profile
 
Old 12-03-2008, 05:45 PM Re: Parsing RSS - removing line breaks
Y-aji's Avatar
Skilled Talker

Posts: 53
Name: Keith
Trades: 0
Oh, thank you, I hadn't noticed that trim() is only for the beginning & end of things. That in itself is very helpful to know.

str_replace() did not originally fix it... I did give str_replace("\r\n","",$this->title) another try, to no avail. until I realized I've wasted a huge amount of time on the title, rather than the subject. I even posted the problem referring to $this->title, rather than $this->description. Thank you again.. I suppose after staring at one thing for 5 straight days, I got careless..

Thank you and sorry for such a dumb fix. My problems always seem to get solved when I post here.

Resolution:
PHP Code:
class rss {
   
//array containing unneccessary page breaks
   
var $order = array("\r\n""\n""\r""chr(13)",  "\t""\0""\x0B");

   
//For title, print the following after stripping everything that is not plain text.
   
printf('<b><a alt="%s">%s</a></b><br />'trim($this->link), addslashes(strip_tags(str_replace($this->order""$this->title))));

   
//For content, print the following after stripping everything that is not plain text.
   
printf("%s"addslashes(strip_tags(str_replace($this->order""$this->description))));

Y-aji is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Parsing RSS - removing line breaks
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting 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 Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.35445 seconds with 12 queries