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
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: So need to figure out if it coming like that from Yahoo or it's being converted after the fact on your end. - Shawn
This is the XML URL: http://news.search.yahoo.com/usns/ynsearch/categories/news_story_search_rss/index.html?p=NFL+Draft
Looks like it's coming from Yahoo like that. If you want them to be bold, simply replace > with > and < with < in your PHP code... or just strip them off if you don't want them to be bold. - Shawn
Shawn, with the code i used, it imports the feed with <b> in text format. Is there a way to block this from occuring>
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("<b>","</b>"); $zf_items[$i]['desc'] = str_replace($errsym, "", $zf_items[$i]['desc']); All it does it looks for <b> and </b> and replaces them with a blank.
<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"> 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?
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("<b>","</b>"); $mover_headline_data[$item_counter]["description"] = str_replace($errsym, "", $mover_headline_data[$item_counter]["description"]); }
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
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>"; } ?>
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("<b>","</b>"); $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>"; } ?>