ulvis.paste.net

Paste Search Dynamic
Recent pastes
RSS script with cache function
  1. <?php
  2. $cache_time = 3600*24; // 24 hours
  3. $cache_file = $_SERVER['DOCUMENT_ROOT'].'/cache/test.rss';
  4. $timedif = @(time() - filemtime($cache_file));
  5. if (file_exists($cache_file) && $timedif < $cache_time) {
  6.     $string = file_get_contents($cache_file);
  7. } else {
  8.     $string = file_get_contents('http://www.ulvis.net/feed/');
  9.     if ($f = @fopen($cache_file, 'w')) {
  10.         fwrite ($f, $string, strlen($string));
  11.         fclose($f);
  12.     }
  13. }
  14. $xml = simplexml_load_string($string);
  15. // place the code below somewhere in your html
  16. <div id="rssbox">
  17.    <ul>';
  18. $count = 0;
  19. $max = 3;
  20. // the next object is an example for a feed from wordpress
  21. foreach ($xml->channel->item as $val) {
  22.     if ($count < $max) {
  23.         echo '
  24.        <li>
  25.            <strong>'.$val->title.'</strong><br />
  26.            '.$val->description.' | <a href="'.$val->link.'">More  &gt;</a>
  27.        </li>';
  28.     }
  29.     $count++;
  30. }
  31.    </ul>
  32. </div>';
Parsed in 0.024 seconds