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.

Using an RSS Feed (This is Easy)

Discussion in 'XML & RSS' started by yfs1, Jan 5, 2005.

  1. noppid

    noppid gunnin' for the quota

    Messages:
    4,246
    Likes Received:
    232
    Best Answers:
    0
    Trophy Points:
    135
    #81
    Save a few news feed links. You will find most are dead in a week to a month. Not much worth archiving. :/
     
    noppid, Apr 3, 2005 IP
  2. TheWebJunkie

    TheWebJunkie Banned

    Messages:
    630
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #82
    Ive tried adding rss feed to my site and i get this error

    XML error: junk after document element at line 50

    here my index page code

    
    <?php
    error_reporting(E_ALL);
    
    require_once 'PHProxy.class.php';
    
    $PHProxy = new PHProxy(isset($_GET['flags']) ? $_GET['flags'] : null);
    
    if (isset($_GET['url']))
    {
        $PHProxy->start_transfer($_GET['url']);
        echo $PHProxy->return_response();
        exit();
    }
    
    if (isset($_GET['action'], $_GET['delete']) && $_GET['action'] == 'cookies')
    {
        $PHProxy->delete_cookies($_GET['delete']);
        header("Location: $PHProxy->script_url?action=cookies");
        exit();
    }
    
    if (isset($_POST['username'], $_POST['password'], $_POST['server'], $_POST['realm'], $_POST['auth_url']))
    {
        $PHProxy->request_method = 'GET';
        $PHProxy->url_segments['host'] = $PHProxy->decode_url($_POST['server']);
        $PHProxy->set_authorization($_POST['username'], $_POST['password']);
        $PHProxy->start_transfer($_POST['auth_url']);
        echo $PHProxy->return_response();
        exit();
    }
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US">
    <head>
      <title>NoMoreLimits</title>
      <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
      <link rel="stylesheet" type="text/css" href="style.css" media="all" />
      <script src="javascript.js" type="text/javascript"></script>
    </head>
    <body>
    <center><div class="smallfont">NoMoreLimits resides on a fast dedicated server provided by <a href="http://www.perfectsql.com" target="_blank">PerfectSQL</a></div><br><a href="http://www.nomorelimits.net/siterefer/sr_form.php" target="_blank"><b>Recommend this site to a mate!</b></a></center>
    <div id="container">
      <div id="menu"><a href="<?php echo $_SERVER['PHP_SELF'] ?>">URL Form</a> | <a href="?action=cookies">Manage Cookies</a></div>
      <div class="title">NoMoreLimits</div>
    <?php
    
    if (isset($_GET['error']))
    {
        echo '<div class="error"><b>Error:</b> ' . $_GET['error'] . '</div>';
    }
    
    if (isset($_GET['action']))
    {
        if ($_GET['action'] == 'cookies')
        {
            $cookies = $PHProxy->get_cookies('COOKIE', false);
    
            if (!empty($cookies))
            {
                echo '<table style="width: 100%">';
                echo '<tr><td class="option" colspan="5"><a href="?action=cookies&delete=all">Clear All Cookies</a></td></tr>';
                echo '<tr><td class="head">Name</td><td class="head">Domain</td><td class="head">Path</td><td class="head">Value</td><td class="head">Action</td></tr>';
    
                for ($i = 0; $i < count($cookies); $i++)
                {
                    $j = $i&1 ? ' class="shade"' : '';
                    echo "<tr><td$j>{$cookies[$i][0]}</td><td$j>{$cookies[$i][1]}</td><td$j>{$cookies[$i][2]}</td>"
                       . "<td$j>{$cookies[$i][3]}</td><td$j><a href=". '"?action=cookies&delete='. md5(implode('', $cookies[$i])) . '">delete</a></td></tr>';
                }
    
                echo '</table>';
            }
            else
            {
                echo '<div class="error">No cookies available.</div>';
            }
        }
        else if ($_GET['action'] == 'auth' && isset($_GET['server'], $_GET['realm'], $_GET['auth_url']))
        {
            echo '<form method="post" action="' . $_SERVER['PHP_SELF'] . '">';
            echo '<input type="hidden" name="server" value="'. $_GET['server'] .'" />';
            echo '<input type="hidden" name="realm" value="'. $_GET['realm'] .'" />';
            echo '<input type="hidden" name="auth_url" value="'. $_GET['auth_url'] .'" />';
            echo '<table style="width: 100%">';
            echo '<tr><td colspan="2" class="option">Enter user name and password for <b>' . $_GET['realm'] . '</b> at <i>' . $PHProxy->decode_url($_GET['server']) . '</i></td></tr>';
            echo '<tr><td width="30%" class="option">User name</td><td class="option"><input type="text" name="username" value="" /></td></tr>';
            echo '<tr><td width="30%" class="option">Password</td><td class="option"><input type="password" name="password" value="" /></td></tr>';
            echo '<tr><td colspan="2" style="text-align: center"><input type="submit" value="OK" /></td></tr>';
            echo '</table>';
            echo '</form>';
        }
    } 
    else
    {
      ?>
      <form name="proxy_form" method="get" action="<?php echo $_SERVER['PHP_SELF'] ?>">
      <input type="hidden" name="url" value="" />
      <input type="hidden" name="flags" value="" />
      </form>
      <form name="settings" method="get" action="" onsubmit="return submit_form();">
      <table style="width: 100%">
      <tr><td class="option" style="width: 20%">URL</td><td class="option" style="width: 80%">&nbsp;<input type="text" name="url" size="70" value="" /></td></tr>
      <?php echo $PHProxy->options_list(true, true) ?>
      </table>
      <div style="text-align: center"><input type="checkbox" name="new_window" />New Window <input type="submit" name="browse" value="Browse" onclick="return submit_form();" /><input type="reset" value="Reset Form" /></div>
      <div style="text-align: center"><a href="http://sourceforge.net/projects/poxy/">PHProxy</a> <?php echo $PHProxy->version ?> Copyright 2004 <a href="http://www.whitefyre.com/">ultimategamer00</a></div>
      </form><br><p> Partner Links: <a href="http://www.talkpixar.com"><font color="#FF0000"><b>D</b></font></a><a target="_blank" href="http://www.talkpixar.com"><font color="#FF0000"><b>isney 
    Pixar forums</b></font></a><font color="#FF0000"></font></b></font> | <a href="http://www.babe-forum.com"><b>Babe Forum - Hot pics and chat</b></a> || <a href="http://www.sigtraders.com"><b>Sigtraders</b></a> || <a href="http://www.thejosher.com">TheJosher</a> || <a href="http://www.alldotnet.com/">All Dot Net Search Directory</a> || <?php include('http://www.globalfusion.com.au/linkhost.php'); ?> | <a href="http://www.yoga-for-health.net">Yoga</a> | <a href="http://www.jonwheatley.co.uk">Jon Wheatley</a>
    </p>
    <br>
    <center><script type="text/javascript"><!--
    google_ad_client = "pub-xxxxxxxxxxxxxxx";
    google_ad_width = 728;
    google_ad_height = 90;
    google_ad_format = "728x90_as";
    google_ad_type = "text";
    google_ad_channel ="";
    google_color_border = "FF0000";
    google_color_bg = "FFFF00";
    google_color_link = "FF0000";
    google_color_url = "0000FF";
    google_color_text = "000000";
    //--></script>
    <script type="text/javascript"
      src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script></center><br><?php
    $insideitem = false;
    $tag = "";
    $title = "";
    $description = "";
    $link = "";
    $locations = array('http://www.computerworld.com/news/xml/6/0,5009,,00.xml');
    srand((float) microtime() * 10000000); // seed the random gen 
    $random_key = array_rand($locations);
    function startElement($parser, $name, $attrs) {
     global $insideitem, $tag, $title, $description, $link;
     if ($insideitem) {
      $tag = $name;
     } elseif ($name == "ITEM") {
      $insideitem = true;
     }
    }
    function endElement($parser, $name) {
     global $insideitem, $tag, $title, $description, $link;
     if ($name == "ITEM") {
      printf("<dt><b><a href='%s' target='new' rel='nofollow'>%s</a></b></dt>",
      trim($link),htmlspecialchars(trim($title)));
      printf("<dt>%s</dt><br><br>",htmlspecialchars(trim($description)));
      $title = "";
      $description = "";
      $link = "";
      $insideitem = false;
     }
    }
    function characterData($parser, $data) {
     global $insideitem, $tag, $title, $description, $link;
     if ($insideitem) {
     switch ($tag) {
      case "TITLE":
      $title .= $data;
      break;
      case "DESCRIPTION":
      $description .= $data;
      break;
      case "LINK":
      $link .= $data;
      break;
     }
     }
    }
    $xml_parser = xml_parser_create();
    xml_set_element_handler($xml_parser, "startElement", "endElement");
    xml_set_character_data_handler($xml_parser, "characterData");
    $fp = fopen($locations[$random_key], 'r')
     or die("Error reading RSS data.");
    $int = 0;
    while ($int != 6){
    $data = fread($fp, 1024);
    xml_parse($xml_parser, $data, feof($fp))
    or die(sprintf("XML error: %s at line %d",
    xml_error_string(xml_get_error_code($xml_parser)),
    xml_get_current_line_number($xml_parser)));
    
    $int++;
    }
    fclose($fp);
    
    xml_parser_free($xml_parser);
    
    ?>
      <?php
    }
    
    echo '</div></body></html>';
    ?>
    
    PHP:
     
    TheWebJunkie, Apr 12, 2005 IP
  3. Padawan

    Padawan Peon

    Messages:
    1,085
    Likes Received:
    70
    Best Answers:
    0
    Trophy Points:
    0
    #83
    No, I didn't get an answer. What I did was copy the news each day to a new static web page and built up my own archive that way - not ideal but still helps build up some content quickly. :)
     
    Padawan, Apr 13, 2005 IP
  4. Jez

    Jez Well-Known Member

    Messages:
    532
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    138
    #84
    Hi yfs1,

    Thanks for this code! I have had great success on my blog with it http://www.hitfix.co.uk/blog it was just the answer I had been looking for for a while.

    I have another question though that no one else seems to know how to fix :

    I want to put your feed code onto a recip directory as an experiment - the pages get created by Arelis and all seems to work like a charm until Arelis adds the sub directory name to the RSS feed:

    typically something like this in bold

    <?php
    $insideitem = false;
    $tag = "";
    $title = "";
    $description = "";
    $link = "";
    function startElement($parser, $name, $attrs) {
    global $insideitem, $tag, $title, $description, $link;
    if ($insideitem) {
    $tag = $name;
    } elseif ($name == "ITEM") {
    $insideitem = true;
    }
    }
    function endElement($parser, $name) {
    global $insideitem, $tag, $title, $description, $link;
    if ($name == "ITEM") {
    printf("<dt><b><a href='%s' target='new' rel='nofollow'>%s</a></b></dt>",
    trim($link),htmlspecialchars(trim($title)));
    printf("<dt>%s</dt><br><br>",htmlspecialchars(trim($description)));
    $title = "";
    $description = "";
    $link = "";
    $insideitem = false;
    }
    }
    function characterData($parser, $data) {
    global $insideitem, $tag, $title, $description, $link;
    if ($insideitem) {
    switch ($tag) {
    case "TITLE":
    $title .= $data;
    break;
    case "DESCRIPTION":
    $description .= $data;
    break;
    case "LINK":
    $link .= $data;
    break;
    }
    }
    }
    $xml_parser = xml_parser_create();
    xml_set_element_handler($xml_parser, "startElement", "endElement");
    xml_set_character_data_handler($xml_parser, "characterData");
    $fp = fopen("http://news.search.yahoo.com/news/rss?ei=UTF-8&p=Sub Directory","r")
    or die("Error reading RSS data.");
    while ($data = fread($fp, 4096))
    xml_parse($xml_parser, $data, feof($fp))
    or die(sprintf("XML error: %s at line %d",
    xml_error_string(xml_get_error_code($xml_parser)),
    xml_get_current_line_number($xml_parser)));
    fclose($fp);
    xml_parser_free($xml_parser);
    ?>

    As you can see Arelis adds the sub directory name with a space and not a "+" and the yahoo search therefore doesn't recognise it.

    My question is - is there a way to strip out the "space" and replace with "+" just in that line? Remember that after being created each page (or RSS feed code) will have a different sub directory name - perhaps something like "Cross Trainers UK" needing to be "Cross+Trainers+UK" - I don't know enough about php to know whether this is impossible or not.

    I hope I have explained myself clearly!

    Your reply would be appreciated if only to stop me timkering about with it to try to make it work if it's not possible.

    Thanks,

    Jez.
     
    Jez, Apr 15, 2005 IP
  5. neterslandreau

    neterslandreau Peon

    Messages:
    279
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #85
    www.php.net/urlencode
    www.php.net/urldecode
     
    neterslandreau, Apr 15, 2005 IP
  6. ZenithalRavage

    ZenithalRavage Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #86
    This code is great!
    I can get it to work like a charm in it's own php page (www.a-base.dds.nl/forum/rsstest.php), but I'm trying to get it into a seperate vbulletin page without success at the moment (www.a-base.dds.nl/forum/news.php).

    As you can see it seems like it's just echoing out the code or something, does anybody have a clue as how to get this to work?
     
    ZenithalRavage, May 5, 2005 IP
  7. dirtdog1960theone

    dirtdog1960theone Active Member

    Messages:
    124
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    58
    #87
    Did not work durn it. I cut and pasted the code into a test html page and uploaded it.

    When I view the page I just see the code displayed.

    First thing viewable:

    %s", trim($link),htmlspecialchars(trim($title))); printf("
    %s


    ",htmlspecialchars(trim

    down to the last lline

    xml_parser_free($xml_parser); ?>

    Am doing soemthing incorrectly? I tried two differnet hosts.

    Does this mean they don't enable php?

    Thanks Dan

    added just saw the post above, I named the file index.html do I have to give it a .php extension?
     
    dirtdog1960theone, May 6, 2005 IP
  8. Texacola

    Texacola Peon

    Messages:
    16
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #88
    dirdog you probably will have to add the following to your .htaccess file, on a line by itself

    AddType application/x-httpd-php .htm .html

    google how to if not sure. It's what I had to do to get my php inside html to work
     
    Texacola, May 6, 2005 IP
  9. DangerMouse

    DangerMouse Peon

    Messages:
    275
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #89
    Was saying this to the poster above yours - sorry :$

    I think he's trying to run it in a php page though: www.a-base.dds.nl/forum/news.php

    Only thing I can think... Have you encapsulated the code in your <? php tags ?> ?
     
    DangerMouse, May 6, 2005 IP
  10. ZenithalRavage

    ZenithalRavage Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #90
    Hello,
    yes the php tags are correct. It seems I can't just copy paste this whole code into this news template I made because I think it's conflicting with the existing vbulletin code but I have no idea how to solve this, my php knowledge is too limited for that :eek:
    Maybe there are others here who have succesfully used this code on a vbulletin page?
     
    ZenithalRavage, May 6, 2005 IP
  11. mopacfan

    mopacfan Peon

    Messages:
    3,273
    Likes Received:
    164
    Best Answers:
    0
    Trophy Points:
    0
    #91
    This thread, even do dealing with php, was very useful. I was able to find a good feed for my site and I also found a company with whom I can set up an affiliate program that will be perfectly suited for my site. Thanks YFS1
     
    mopacfan, May 6, 2005 IP
  12. dirtdog1960theone

    dirtdog1960theone Active Member

    Messages:
    124
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    58
    #92
    Thanks Texacola. No I don't know how to do it. I don't see the .htaccess file from the ftp program so I am stumped.

    Thanks DangerMouse. I don't know anything about the link in ZR's thread. My question was about the file extension I noticed ZR using php vs html.

    I am assuming the errors are due to the hosting companies not enabling php <shrug>. I am going to email the two hosting companies I use and ask them about this code.

    Anything else I should ask? Like adding AddType application/x-httpd-php .htm .html Texacloa mentioned?

    One hosting company will start a series of mindless emails strings till they get the question to a tech, and then will want more money. :p
    The other will ignore me until they are out of money. :rolleyes:
     
    dirtdog1960theone, May 6, 2005 IP
  13. DangerMouse

    DangerMouse Peon

    Messages:
    275
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #93
    If there isn't already an .htaccess file there - try making one. it's just a text file - nothing else is needed other than this line

    AddType application/x-httpd-php .htm .html

    If that doesn't work... your host might not allow it... I would ask them anyway
     
    DangerMouse, May 6, 2005 IP
  14. Jez

    Jez Well-Known Member

    Messages:
    532
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    138
    #94
    Thanks Neters Landreau,

    Unfortunately I still can't get it to work! :confused:

    I will get there eventually I guess - I just need to know a little bit more than nothing at all about PHP!

    I have passed it onto a friend with a little more knowledge than me - hopefully he will be able to implement the urlencode.
     
    Jez, May 6, 2005 IP
  15. dirtdog1960theone

    dirtdog1960theone Active Member

    Messages:
    124
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    58
    #95
    Thanks did that. For anybody trying to get this to work I tried both:

    AddHandler application/x-httpd-php .html .htm
    AddType application/x-httpd-php .htm .html

    The seems to start at or around the line

    It creates an html link to my directory with the tag % sign as the link text.

    prints out printf("<dt><b><a href='%s'>%s</a></b></dt>", and all text after that.
     
    dirtdog1960theone, May 7, 2005 IP
  16. HostingInsider

    HostingInsider Guest

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #96
    My Blogger blog's RSS wouldn't work on the code that is listed at SitePoint, but my PHPBB RSS feed would.
     
    HostingInsider, May 7, 2005 IP
  17. letsmakeamillion

    letsmakeamillion Well-Known Member

    Messages:
    319
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    108
    #97
    Thanks for this BLOCKBUSTER tip. Been searching for how to implement this on my .html pages for MONTHS.

    Just added a little to your rep points :)
     
    letsmakeamillion, Jun 8, 2005 IP
  18. yfs1

    yfs1 User Title Not Found

    Messages:
    13,798
    Likes Received:
    922
    Best Answers:
    0
    Trophy Points:
    0
    #98
    Cheers,

    Of course be sure to read this thread in its entirity (if you are using it) as there are different issues brought up. My post was merely to provide the code to do it. You can decide for yourself whether to implement it or not ;)
     
    yfs1, Jun 8, 2005 IP
  19. bentong

    bentong Banned

    Messages:
    3,543
    Likes Received:
    257
    Best Answers:
    0
    Trophy Points:
    0
    #99
    thanks for the good resource..a great big help to all members wanted to start a feed.
     
    bentong, Jun 8, 2005 IP
  20. Hodgedup

    Hodgedup Notable Member

    Messages:
    3,962
    Likes Received:
    287
    Best Answers:
    0
    Trophy Points:
    203
    #100
    Nice job yfs1 and everyone else that has provided enhancements.

    I started reading the first page of the thread and I when I came to the terms "straight" and "rotating" rss feed. I typed "difference between rotating feed and straight feed" into Goggle and page 2 of the thread came up number 1. lol. I guess I should have just read through the entire thread first.
     
    Hodgedup, Jun 8, 2005 IP