473,657 Members | 2,515 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Stripping HTML from RSS feed

First things first, let me say that I couldn't decide whether to post
this to the PHP ng, or to an XML ng. I know from experience that you
guys know what you're talking about, though, and all of the questions
mean "how to do this in PHP," so I hope I picked the right one ;-)

For about a year, I've been importing Yahoo News headlines into my site
via their RSS feed. But I would much rather import Google News
headlines because I can make them specific to my location. The problem
is that their RSS feed includes HTML, and the script I use can't figure
it out.

Here's an example tag from their most recent feed:

<description><b r><table border=0 width= valign=top cellpadding=2
cellspacing=7>< tr><td valign=top><a
href="http://news.google.com/news/url?sa=T&ct=us/0-0&fd=R&url=http ://www.raleighchro nicle.com/2006072105.html &cid=1108150860 &ei=hUzBRO_JMpe 2aInH4PsB">Truc k
Driver Wins $100,000 In Lottery; <b>NC</bPowerball
Winners</a><br><font size=-1><font color=#6f6f6f>R aleigh
Chronicle,&nbsp ;NC&nbsp;-</font<nobr>2 hours
ago</nobr></font><br><font size=-1>REIDSVILLE -- According to the
<b>NC</bLottery Commission, when Dennis Mebane collected his prize
this week from a winning $100,000 instant scratch-off ticket, he
<b>...</b</font><br></table></description>
The XML tag is <description> , but the script I use to parse it
(rss2array, a cookie-cutter script that I downloaded) can't
differentiate between <descriptiona nd <table>. Usually, I would call
<descriptionb y using the variable $rss['items'][$i]['description']
(where $i is the index counter), but with this output I would have to
do something like
$rss['items'][$i]['description']['table'><'tr'>< 'td'><'b><'font '>...

So I guess I really have 2 questions:

1. Is there a way to strip HTML completely out of the tag? Or better
yet, to make rss2array read the HTML as actual HTML instead of XML
tags?

2. If not, is there a better way to read the XML than through the use
of rss2array? I'm a fairly experienced coder, but don't really use XML
often enough to have a good grasp of the logic.

TIA,

Jason

Jul 21 '06 #1
3 2414
See if this works:

1. Use $rss['items'][$i]['description'] to return the contents of the
description node (including html markup) as a string.
2. Use the 'strip_tags' function to remove unwanted HTML from the
returned string.

See http://www.php.net/manual/en/function.strip-tags.php for more info.

Jason wrote:
First things first, let me say that I couldn't decide whether to post
this to the PHP ng, or to an XML ng. I know from experience that you
guys know what you're talking about, though, and all of the questions
mean "how to do this in PHP," so I hope I picked the right one ;-)

For about a year, I've been importing Yahoo News headlines into my site
via their RSS feed. But I would much rather import Google News
headlines because I can make them specific to my location. The problem
is that their RSS feed includes HTML, and the script I use can't figure
it out.

Here's an example tag from their most recent feed:

<description><b r><table border=0 width= valign=top cellpadding=2
cellspacing=7>< tr><td valign=top><a
href="http://news.google.com/news/url?sa=T&ct=us/0-0&fd=R&url=http ://www.raleighchro nicle.com/2006072105.html &cid=1108150860 &ei=hUzBRO_JMpe 2aInH4PsB">Truc k
Driver Wins $100,000 In Lottery; <b>NC</bPowerball
Winners</a><br><font size=-1><font color=#6f6f6f>R aleigh
Chronicle,&nbsp ;NC&nbsp;-</font<nobr>2 hours
ago</nobr></font><br><font size=-1>REIDSVILLE -- According to the
<b>NC</bLottery Commission, when Dennis Mebane collected his prize
this week from a winning $100,000 instant scratch-off ticket, he
<b>...</b</font><br></table></description>
The XML tag is <description> , but the script I use to parse it
(rss2array, a cookie-cutter script that I downloaded) can't
differentiate between <descriptiona nd <table>. Usually, I would call
<descriptionb y using the variable $rss['items'][$i]['description']
(where $i is the index counter), but with this output I would have to
do something like
$rss['items'][$i]['description']['table'><'tr'>< 'td'><'b><'font '>...

So I guess I really have 2 questions:

1. Is there a way to strip HTML completely out of the tag? Or better
yet, to make rss2array read the HTML as actual HTML instead of XML
tags?

2. If not, is there a better way to read the XML than through the use
of rss2array? I'm a fairly experienced coder, but don't really use XML
often enough to have a good grasp of the logic.

TIA,

Jason
Jul 22 '06 #2
I'm afraid that didn't work. It reads the variable as empty.

As a test, I tried print_r($rss), and while it reads everything else
correctly, it shows ['description'] as an empty variable. The only ones
that it reads correctly are the ones that don't have HTML.

Knowing this, it's got to be a "problem" with rss2array. I put
"problem" in quotes, because technically I think it's the XML file
that's flawed, but there's not much I can do about that. What other way
can I parse an XML database using PHP?

- Jason
See if this works:

1. Use $rss['items'][$i]['description'] to return the contents of the
description node (including html markup) as a string.
2. Use the 'strip_tags' function to remove unwanted HTML from the
returned string.

See http://www.php.net/manual/en/function.strip-tags.php for more info.

Jason wrote:
First things first, let me say that I couldn't decide whether to post
this to the PHP ng, or to an XML ng. I know from experience that you
guys know what you're talking about, though, and all of the questions
mean "how to do this in PHP," so I hope I picked the right one ;-)

For about a year, I've been importing Yahoo News headlines into my site
via their RSS feed. But I would much rather import Google News
headlines because I can make them specific to my location. The problem
is that their RSS feed includes HTML, and the script I use can't figure
it out.

Here's an example tag from their most recent feed:

<description><b r><table border=0 width= valign=top cellpadding=2
cellspacing=7>< tr><td valign=top><a
href="http://news.google.com/news/url?sa=T&ct=us/0-0&fd=R&url=http ://www.raleighchro nicle.com/2006072105.html &cid=1108150860 &ei=hUzBRO_JMpe 2aInH4PsB">Truc k
Driver Wins $100,000 In Lottery; <b>NC</bPowerball
Winners</a><br><font size=-1><font color=#6f6f6f>R aleigh
Chronicle,&nbsp ;NC&nbsp;-</font<nobr>2 hours
ago</nobr></font><br><font size=-1>REIDSVILLE -- According to the
<b>NC</bLottery Commission, when Dennis Mebane collected his prize
this week from a winning $100,000 instant scratch-off ticket, he
<b>...</b</font><br></table></description>
The XML tag is <description> , but the script I use to parse it
(rss2array, a cookie-cutter script that I downloaded) can't
differentiate between <descriptiona nd <table>. Usually, I would call
<descriptionb y using the variable $rss['items'][$i]['description']
(where $i is the index counter), but with this output I would have to
do something like
$rss['items'][$i]['description']['table'><'tr'>< 'td'><'b><'font '>...

So I guess I really have 2 questions:

1. Is there a way to strip HTML completely out of the tag? Or better
yet, to make rss2array read the HTML as actual HTML instead of XML
tags?

2. If not, is there a better way to read the XML than through the use
of rss2array? I'm a fairly experienced coder, but don't really use XML
often enough to have a good grasp of the logic.

TIA,

Jason
Jul 22 '06 #3
There are two things I can suggest:

1. Using the DOM XML functions to extract the values (See
http://au3.php.net/domxml), then use the strip_tags() functions.
or
2. Use Regular expressions to extract the html tags from the XML before
you use rss2array

e.g.

// Remove all <ptags
$xml = preg_replace('/<p(.*)?>(.*)? <\/p>/', "$2", $xml);

//Remove all <fonttags
$xml = preg_replace('/<font(.*)?>(.*) ?<\/font>/', "$2", $xml);

//etc...
Jason wrote:
I'm afraid that didn't work. It reads the variable as empty.

As a test, I tried print_r($rss), and while it reads everything else
correctly, it shows ['description'] as an empty variable. The only ones
that it reads correctly are the ones that don't have HTML.

Knowing this, it's got to be a "problem" with rss2array. I put
"problem" in quotes, because technically I think it's the XML file
that's flawed, but there's not much I can do about that. What other way
can I parse an XML database using PHP?

- Jason
See if this works:

1. Use $rss['items'][$i]['description'] to return the contents of the
description node (including html markup) as a string.
2. Use the 'strip_tags' function to remove unwanted HTML from the
returned string.

See http://www.php.net/manual/en/function.strip-tags.php for more info.

Jason wrote:
First things first, let me say that I couldn't decide whether to post
this to the PHP ng, or to an XML ng. I know from experience that you
guys know what you're talking about, though, and all of the questions
mean "how to do this in PHP," so I hope I picked the right one ;-)
>
For about a year, I've been importing Yahoo News headlines into my site
via their RSS feed. But I would much rather import Google News
headlines because I can make them specific to my location. The problem
is that their RSS feed includes HTML, and the script I use can't figure
it out.
>
Here's an example tag from their most recent feed:
>
<description><b r><table border=0 width= valign=top cellpadding=2
cellspacing=7>< tr><td valign=top><a
href="http://news.google.com/news/url?sa=T&ct=us/0-0&fd=R&url=http ://www.raleighchro nicle.com/2006072105.html &cid=1108150860 &ei=hUzBRO_JMpe 2aInH4PsB">Truc k
Driver Wins $100,000 In Lottery; <b>NC</bPowerball
Winners</a><br><font size=-1><font color=#6f6f6f>R aleigh
Chronicle,&nbsp ;NC&nbsp;-</font<nobr>2 hours
ago</nobr></font><br><font size=-1>REIDSVILLE -- According to the
<b>NC</bLottery Commission, when Dennis Mebane collected his prize
this week from a winning $100,000 instant scratch-off ticket, he
<b>...</b</font><br></table></description>
>
>
The XML tag is <description> , but the script I use to parse it
(rss2array, a cookie-cutter script that I downloaded) can't
differentiate between <descriptiona nd <table>. Usually, I would call
<descriptionb y using the variable $rss['items'][$i]['description']
(where $i is the index counter), but with this output I would have to
do something like
$rss['items'][$i]['description']['table'><'tr'>< 'td'><'b><'font '>...
>
So I guess I really have 2 questions:
>
1. Is there a way to strip HTML completely out of the tag? Or better
yet, to make rss2array read the HTML as actual HTML instead of XML
tags?
>
2. If not, is there a better way to read the XML than through the use
of rss2array? I'm a fairly experienced coder, but don't really use XML
often enough to have a good grasp of the logic.
>
TIA,
>
Jason
Jul 22 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1732
by: Steveo | last post by:
I am currently stripping HTML from a string with the following code. (I know it's not the best way to strip HTML but bear with me) re.compile("<.*?>") I wanted to allow all H1 and H2 tags so i changed it to: re.compile("<*?>") This seemed to work but it also allowed the HTML tag(basically anythin
7
2569
by: Dan Stromberg | last post by:
I'm working on writing a program that will synchronize one database with another. For the source database, we can just use the python sybase API; that's nice and normal. For the target database, unfortunately, the only interface we have access to, is http+html based. There's same javascript involved too, but hopefully we won't have to interact with that. So, I've got Basic AUTH going with http, but now I'm faced with the following...
17
29824
by: mickjames | last post by:
Hi, I'd like to include the whole web page content (as opposed to just the headlines) into RSS/XML to enable people to read them via rss feed readers. Question: how to convert HTML elements such as href, img, b, p, etc into XML? I've seen someone use the following in their RSS feed but I don't like it because <pre> doesn't produce a nice format:
2
2282
by: Jukka K. Korpela | last post by:
This question is fairly theoretical (even for me), but it started to puzzle me: According to the SGML declaration for HTML 4.01, at http://www.w3.org/TR/REC-html40/sgml/sgmldecl.html#h-20.1 the Form Feed character, U+000C (12 in decimal), is UNUSED, i.e. forbidden: DESCSET 0 9 UNUSED 9 2 9 11 2 UNUSED
258
8591
by: Terry Andersen | last post by:
If I have: struct one_{ unsigned int one_1; unsigned short one_2; unsigned short one_3; }; struct two_{ unsigned int two_1;
5
2448
by: David Sawyer | last post by:
I am trying to read in an HTML file and strip out the HTML code so that all I have left is the text of the body. Does anyone have any suggestions for doing this? Any HTML stripping routines or objects that perform the function?
4
4152
by: Spondishy | last post by:
Hi, I'm looking for help with a regular expression and c#. I want to remove all tags from a piece of html except the following. <a> <b> <h1> <h2>
19
1826
by: ThatsIT.net.au | last post by:
I come from a classic asp background, but have started using ASP.NET about 12 months ago, but I'm still not sure about the pros and cons of using controls v HTML spat out from code as you would in classic asp. I have also been using System.Web.UI.ICallbackEventHandler to send data to the server and back without using controls. What I want to know is the pros and cons of each. To me you never have quite the freedom using a control as you...
3
1597
by: Michel Bouwmans | last post by:
Hey everyone, I'm trying to strip all script-blocks from a HTML-file using regex. I tried the following in Python: testfile = open('testfile') testhtml = testfile.read() regex = re.compile('<script\b*>(.*?)</script>', re.DOTALL) result = regex.sub('', blaat)
1
8518
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8621
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7354
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6177
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5643
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2743
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1971
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1734
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.