1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Yahoo! RSS feed

Discussion in 'Programming' started by rwhetsto, Mar 25, 2004.

  1. #1
    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
     
    rwhetsto, Mar 25, 2004 IP
  2. digitalpoint

    digitalpoint Overlord of no one Staff

    Messages:
    38,333
    Likes Received:
    2,613
    Best Answers:
    462
    Trophy Points:
    710
    Digital Goods:
    29
    #2
    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
     
    digitalpoint, Mar 25, 2004 IP
  3. rwhetsto

    rwhetsto Peon

    Messages:
    108
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
  4. digitalpoint

    digitalpoint Overlord of no one Staff

    Messages:
    38,333
    Likes Received:
    2,613
    Best Answers:
    462
    Trophy Points:
    710
    Digital Goods:
    29
    #4
    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
     
    digitalpoint, Mar 25, 2004 IP
  5. rwhetsto

    rwhetsto Peon

    Messages:
    108
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Got it fixed, thanks!
     
    rwhetsto, Mar 25, 2004 IP
  6. schlottke

    schlottke Peon

    Messages:
    2,185
    Likes Received:
    63
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Shawn,

    with the code i used, it imports the feed with <b> in text format. Is there a way to block this from occuring>
     
    schlottke, Apr 15, 2004 IP
  7. digitalpoint

    digitalpoint Overlord of no one Staff

    Messages:
    38,333
    Likes Received:
    2,613
    Best Answers:
    462
    Trophy Points:
    710
    Digital Goods:
    29
    #7
    Aren't you filtering them out?

    - Shawn
     
    digitalpoint, Apr 15, 2004 IP
  8. schlottke

    schlottke Peon

    Messages:
    2,185
    Likes Received:
    63
    Best Answers:
    0
    Trophy Points:
    0
    #8
    It isn't filtering the <b> out, how could I go about doing that?
     
    schlottke, Apr 15, 2004 IP
  9. rwhetsto

    rwhetsto Peon

    Messages:
    108
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #9
    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.
     
    rwhetsto, Apr 18, 2004 IP
  10. schlottke

    schlottke Peon

    Messages:
    2,185
    Likes Received:
    63
    Best Answers:
    0
    Trophy Points:
    0
    #10
    <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?
     
    schlottke, Apr 18, 2004 IP
  11. rwhetsto

    rwhetsto Peon

    Messages:
    108
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #11
    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"]);
    }
     
    rwhetsto, Apr 19, 2004 IP
  12. schlottke

    schlottke Peon

    Messages:
    2,185
    Likes Received:
    63
    Best Answers:
    0
    Trophy Points:
    0
    #12
    It doesn't work, just removes the source link and leaves the description still holding the tags.
     
    schlottke, Apr 19, 2004 IP
  13. rwhetsto

    rwhetsto Peon

    Messages:
    108
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #13
    rwhetsto, Apr 19, 2004 IP
  14. rwhetsto

    rwhetsto Peon

    Messages:
    108
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #14
    I can't get the new php file to post. I will just email it to you
     
    rwhetsto, Apr 19, 2004 IP
  15. schlottke

    schlottke Peon

    Messages:
    2,185
    Likes Received:
    63
    Best Answers:
    0
    Trophy Points:
    0
    #15
    it must have gotten emailed incorrectly cuz it didnt bring it up.
     
    schlottke, Apr 22, 2004 IP
  16. rwhetsto

    rwhetsto Peon

    Messages:
    108
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #16
    Did you ever get it working? I will send the file again if you need it.
     
    rwhetsto, May 11, 2004 IP
  17. juicetyger

    juicetyger Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #17
    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>";
    }


    ?>
     
    juicetyger, May 20, 2004 IP
  18. rwhetsto

    rwhetsto Peon

    Messages:
    108
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #18
    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>";
    }


    ?>
     
    rwhetsto, May 20, 2004 IP
  19. juicetyger

    juicetyger Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #19
    That worked awesome! You rock. Here it is in action http://1km1kt.net

    Thanks,

    Keeton
     
    juicetyger, May 21, 2004 IP
  20. rwhetsto

    rwhetsto Peon

    Messages:
    108
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #20
    Excellent, glad to hear it!
     
    rwhetsto, May 22, 2004 IP