RSS help Please

Discussion in 'PHP' started by paul_so40, May 22, 2009.

  1. #1
    Hellow fellow coders,

    I am stuck trying to display rss feeds from my site forum ( vbulletin powerd )

    Bellow is s snippet of the code for where i want it to be displayed.

    The feeds are being displayed at

    http://www.united-gamerz.com/forum/external.php

    What i want is the recent 5 threads to be displayed in the <li> tags e.g.
    <li>Recent post 1 title linked to post</li>
    PHP:

    <div id="box7">
    
    						<h2 class="text2 title2">Recent</h2>						<div class="content">
    
    <div class="box">
    <h3 class="text2">Recent threads on the forum</h3>
    <ul class="ul2">
    <li>recent thread - waiting for rss feed</li>
    
    <li>recent thread - waiting for rss feed</li>
    
    <li>recent thread - waiting for rss feed</li>
    
    <li>recent thread - waiting for rss feed</li>
    
    <li>recent thread - waiting for rss feed</li>
    
    </ul>
    
    </div>
    
    
    PHP:
    Can anyone help and tell me what to do?

    Thanks

    Paul
     
    paul_so40, May 22, 2009 IP
  2. NatalicWolf

    NatalicWolf Peon

    Messages:
    262
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #2
    It would involve some extra code...I can do it for you. Please message me on a instant messenger.:)
     
    NatalicWolf, May 22, 2009 IP
  3. dannet

    dannet Well-Known Member

    Messages:
    864
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    153
    #3
    You need to use any rss parser, I recommend you to try with simplepie.org
     
    dannet, May 22, 2009 IP
  4. NatalicWolf

    NatalicWolf Peon

    Messages:
    262
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Here you go! You didn't need no big libraries, just some basic PREG.
    
    <?PHP
    $Data=file_get_contents('http://www.united-gamerz.com/forum/external.php');
    
    preg_match_all('/\<title\>(.*?)\<\/title\>/',$Data,$Titles);
    preg_match_all('/\<link\>(.*?)\<\/link\>/',$Data,$Links);
    $Titles=array_slice($Titles[1],2); //First 2 are the forum's stuff
    $Links=array_slice($Links[1],2);// Skip two
    
    $URLs=array();
    for($i=0;$i<count($Titles);$i++)
    	$URLs[$Titles[$i]]=$Links[$i]; // Make a new array!
    ?>
    
    <div id="box7">
    
    <h2 class="text2 title2">Recent</h2>
    <div class="content">
        <div class="box">
        <h3 class="text2">Recent threads on the forum</h3>
            <ul class="ul2">
    			<?PHP
    				foreach($URLs as $Title => $Link)
    	 	           echo '<li><a href="'.$Link.'">'.$Title.'</a></li>';
    			?>
    		</ul>
        
        </div>
    
    PHP:
     
    NatalicWolf, May 22, 2009 IP