Cheap Cameras - Kamala - Debt Consolidation - Turquoise Rings - Submit articles

PDA

View Full Version : Yahoo! RSS feed


rwhetsto
Mar 25th 2004, 5:36 am
I just implemented my 1st RSS feeds yesterday. Very cool! I used an espn feed for headline news on my homepage and I used a feed from Yahoo, which gives valid news results for the keywords NFL+draft. Located here:
http://www.fantasyfootballjungle.com/
and here, respectively:
http://www.fantasyfootballjungle.com/news/draftnews.php

Does anyone know why those <b> and </b> tags show up in the Yahoo! feed and, more to the point, what I can do to fix them. I know they're bold tags, but why don't they work properly.

If anyone's interested I can talk a little bit about the discoveries I made on my quest to get the RSS feeds to work, otherwise I will save you the reading time.

Thanks,
Ryan

digitalpoint
Mar 25th 2004, 8:39 am
What is the URL for the feed? On your side, they are showing properly... because if you look in the source, they are like so:


Eli Manning hopes to make &lt;b&gt;NFL&lt;/b&gt; history on &lt;b&gt;draft&lt;/b&gt; day.
So need to figure out if it coming like that from Yahoo or it's being converted after the fact on your end.

- Shawn

rwhetsto
Mar 25th 2004, 10:13 am
This is the XML URL:
http://news.search.yahoo.com/usns/ynsearch/categories/news_story_search_rss/index.html?p=NFL+Draft

digitalpoint
Mar 25th 2004, 10:18 am
Looks like it's coming from Yahoo like that. If you want them to be bold, simply replace &gt; with > and &lt; with < in your PHP code... or just strip them off if you don't want them to be bold.

- Shawn

rwhetsto
Mar 25th 2004, 12:11 pm
Got it fixed, thanks!

schlottke
Apr 15th 2004, 5:25 pm
Shawn,

with the code i used, it imports the feed with <b> in text format. Is there a way to block this from occuring>

digitalpoint
Apr 15th 2004, 5:29 pm
Aren't you filtering them out?

- Shawn

schlottke
Apr 15th 2004, 5:44 pm
It isn't filtering the <b> out, how could I go about doing that?

rwhetsto
Apr 18th 2004, 2:31 pm
Use str_replace in the php code. Refer to this page for help http://www.php.net/str_replace

I had to add these two lines to fix my problem:
$errsym = array("&lt;b&gt;","&lt;/b&gt;");
$zf_items[$i]['desc'] = str_replace($errsym, "", $zf_items[$i]['desc']);

All it does it looks for &lt;b&gt; and &lt;/b&gt; and replaces them with a blank.

schlottke
Apr 18th 2004, 5:09 pm
<html>

<head>
<title>College Wrestling News : Wrestling Articles : Iowa and Minnesota College

Wrestling</title>
<meta NAME="DESCRIPTION" CONTENT="The foremost leader in Internet Based Wrestling News.

Live Chat, Video, Audio, News, Forums, and More. The best interactive experience

online!">
<meta NAME="KEYWORDS" CONTENT="wrestling news high school wrestling news amateur wrestling

news">
<meta name="revisit-after" content="10 days">

<meta name="rating" content="general">
<meta name="Owner" content="Wrestling-Connection">
</head>

<body bgcolor="white" text="black" link="black" vlink="black" alink="black">
<table align="center" border="0" cellpadding="0" cellspacing="0" width="636">
<tr>
<td width="700" height="79">
<p><img src="http://www.wrestling-connection.com/images/wrestlingdirectory.gif"> - <a

href="http://www.wrestling-connection.com">Wrestling Directory</a> I <a

href="http://www.wrestling-connection.com/news/index.php">Wrestling News Main Page</a></p>
</td>
</tr>
<tr>
<td width="700"><table align="center" border="1" cellspacing="0" width="100%"

bordercolordark="white" bordercolorlight="black" cellpadding="0">
<tr>
<td width="80%" bgcolor="#FFFFFF" height="27">
<p><font size="2" face="Comic Sans MS" color="#000000">&nbsp;College Wrestling

News</font></p>
</td>
</tr><tr>
<td width="700">
<table border="0" cellpadding="0" cellspacing="0" width="632">
<tr>
<td width="700">
<table border="0" cellpadding="5" cellspacing="0" width="650">
<tr>
<td width="532">
<table border="0" cellpadding="0" cellspacing="0" width="650">
<tr>
<td width="70%" valign="top">
</td>
</tr>
<?php
if( ! ($fp =

fopen("http://news.search.yahoo.com/usns/ynsearch/categories/news_story_search_rss/index.h

tml?p=%5C%22college+wrestling%5C%22", "r" )) )
die("Couldn't open xml file!");
$item_counter = 0;
$in_item_tag = 0;
$mover_current_tag_state = '';
$mover_headline_data = array();
function startElementHandler( $parser, $element_name, $element_attribs )
{
global $item_counter;
global $in_item_tag;
global $mover_current_tag_state;
global $mover_headline_data;
if( $element_name == "ITEM" )
{
$in_item_tag = 1;
}
if( $in_item_tag == 1 )
{
$mover_current_tag_state = $element_name;
}
else
{
$mover_current_tag_state = '';
}
}
function endElementHandler( $parser, $element_name )
{
global $item_counter;
global $in_item_tag;
global $mover_current_tag_state;
global $mover_headline_data;
$mover_current_tag_state = '';
if( $element_name == "ITEM" )
{
$item_counter++;
$in_item_tag = 0;
}
}
function characterDataHandler( $parser , $data )
{
global $item_counter;
global $in_item_tag;
global $mover_current_tag_state;
global $mover_headline_data;
if( $mover_current_tag_state == '' || $in_item_tag == 0 )
return;
if( $mover_current_tag_state == "TITLE" ) {
$mover_headline_data[$item_counter]["title"] = $data;
}
if( $mover_current_tag_state == "LINK" ) {
$mover_headline_data[$item_counter]["link"] = $data;
}
if( $mover_current_tag_state == "DESCRIPTION" ) {
$mover_headline_data[$item_counter]["description"] = $data;
}
}
if( !($xml_parser = xml_parser_create()) )
die("Couldn't create XML parser!");

xml_set_element_handler($xml_parser, "startElementHandler", "endElementHandler");
xml_set_character_data_handler( $xml_parser , "characterDataHandler" );
while( $data = fread($fp, 4096) )
{
if( !xml_parse($xml_parser, $data, feof($fp)) )
{
break; // get out of while loop if we're done with the file
}
}
xml_parser_free($xml_parser);
printf("<table>");
printf("<tr><th><b>Source</b></th><th><b>Description</b></th></tr>");
for($i=0 ;$i < 20 ; $i++)
{

printf("<tr><td><a href=\"%s\">%s\"</a></td><td> %s<br></td></tr>\n" ,

$mover_headline_data[$i]["link"] ,


$mover_headline_data[$i]["title"] ,


$mover_headline_data[$i]["description"]

);
}
printf("</table>");
?>



What code would I add to remove the <b> </b> and where would it go?

rwhetsto
Apr 19th 2004, 8:01 am
Try substituting the following :

if( $mover_current_tag_state == "DESCRIPTION" ) {
$mover_headline_data[$item_counter]["description"] = $data;
}

with:

if( $mover_current_tag_state == "DESCRIPTION" ) {
$mover_headline_data[$item_counter]["description"] = $data;
$errsym = array("&lt;b&gt;","&lt;/b&gt;");
$mover_headline_data[$item_counter]["description"] = str_replace($errsym, "", $mover_headline_data[$item_counter]["description"]);
}

schlottke
Apr 19th 2004, 10:10 am
It doesn't work, just removes the source link and leaves the description still holding the tags.

rwhetsto
Apr 19th 2004, 7:14 pm
It works for me:

Check
http://www.fantasyfootballjungle.com/test_area/newstest.php
This page has the changes, and has no <b> or </b> tags in the description.

Compared to
http://www.fantasyfootballjungle.com/test_area/newstestold.php
which is the original and shows the tags.

I will follow this post with the new php file.

Let me know if it works.

-Ryan

rwhetsto
Apr 19th 2004, 7:43 pm
I can't get the new php file to post. I will just email it to you

schlottke
Apr 22nd 2004, 10:50 pm
it must have gotten emailed incorrectly cuz it didnt bring it up.

rwhetsto
May 11th 2004, 7:28 am
Did you ever get it working? I will send the file again if you need it.

juicetyger
May 20th 2004, 7:29 pm
Can you help me with the same problem? How would I configure this code to exclude the <b></b> tags?

<?php
define('MAGPIE_DIR', '/home/nkm1kt2/public_html/magpie/');

require_once(MAGPIE_DIR.'rss_fetch.inc');
$url = 'http://news.search.yahoo.com/usns/ynsearch/categories/news_story_search_rss/index.html?p=roleplaying';
if ( $url ) {$num_items = 5;
$rss = fetch_rss( $url );
$items = array_slice($rss->items, 1, $num_items);
echo "<p>";
foreach ($items as $item) {

$href = $item['link'];
$title = $item['title'];
$description = $item['description'];
$modified = $item['modified'];
$atom_content = $item['atom_content'];

echo "<a href=$href target='_blank'><b><u>$title</u></b></a><br>$modified$atom_content$description<br>";
}
echo "</p>";
}


?>

rwhetsto
May 20th 2004, 8:06 pm
I think this should work. Make sure the copy and paste works correctly. This only gets rid of the bold text in the description area, which is what I assume you want. Let me know how it works.

<?php
define('MAGPIE_DIR', '/home/nkm1kt2/public_html/magpie/');

require_once(MAGPIE_DIR.'rss_fetch.inc');
$url = 'http://news.search.yahoo.com/usns/ynsearch/categories/news_story_search_rss/index.html?p=roleplaying';
if ( $url ) {$num_items = 5;
$rss = fetch_rss( $url );
$items = array_slice($rss->items, 1, $num_items);
echo "<p>";
foreach ($items as $item) {

$href = $item['link'];
$title = $item['title'];
$description = $item['description'];
$modified = $item['modified'];
$atom_content = $item['atom_content'];

//added code to 'delete' the <b> and </b> tags
$errsym = array("&lt;b&gt;","&lt;/b&gt;");
$description = str_replace($errsym, "", $description);
//end added code

echo "<a href=$href target='_blank'><b><u>$title</u></b></a><br>$modified$atom_content$description<br>";
}
echo "</p>";
}


?>

juicetyger
May 21st 2004, 5:52 am
That worked awesome! You rock. Here it is in action http://1km1kt.net

Thanks,

Keeton

rwhetsto
May 22nd 2004, 10:50 am
Excellent, glad to hear it!

DarrenC
Apr 14th 2005, 7:52 pm
What's the URL to add your own Yahoo rss feed? Can't find a link anywhere! :)