Hello all, I'm using this code below...
I'm using it to push a blog to my site, but i cant seem to get it to work. I'll type out now exactly what I'm doing so you can point out where I'm going wrong. This is the first time I've played with php so I dont know if what I'm doing is right or wrong.PHP Code:<?php
$cache_time = 3600*24; // 24 hours
$cache_file = $_SERVER['DOCUMENT_ROOT'].'/cache/test.rss';
$timedif = @(time() - filemtime($cache_file));
if (file_exists($cache_file) && $timedif < $cache_time) {
$string = file_get_contents($cache_file);
} else {
$string = file_get_contents('http://www.web-development-blog.com/feed/');
if ($f = @fopen($cache_file, 'w')) {
fwrite ($f, $string, strlen($string));
fclose($f);
}
}
$xml = simplexml_load_string($string);
// place the code below somewhere in your html
echo '
<div id="rssbox">
<ul>';
$count = 0;
$max = 3;
// the next object is an example for a feed from wordpress
foreach ($xml->channel->item as $val) {
if ($count < $max) {
echo '
<li>
<strong>'.$val->title.'</strong><br />
'.$val->description.' | <a href="'.$val->link.'">More ></a>
</li>';
}
$count++;
}
echo '
</ul>
</div>';
?>
1. I open my html dreamweaver document where I want to show this blog feed
2. I place the above code in where I want it to appear on the page
3. I edit the '$string = file_get_contents' to my blog address
4. I select save as and change the .html extension to .php
5. I preview the page in my browser and there is no blog there and the bottom third of the code literally shows up on the page preview
Where am I going wrong?
Thanks in advance for any help.



Reply With Quote

Bookmarks