<?php
// Please note that the file is saved as rss.php and the xml code is included in it.
// Include necessary files
include_once '../inc/function.inc.php';
include_once '../inc/db.inc.php';
// Till here no problem
// Open a database connection
$db = new PDO(DB_INFO, DB_USER, DB_PASS);
// When i connect to database I get error.
// in Internet Explorer: This feed contains code error
//in Mozila: Its pops up a rss.php and asks me to open it and save to a specific location
/in Chrome: It displays all the code as it is in the Browser
// Load all blog entries
$e = retrieveEntries($db, 'blog');
// Remove the fulldisp flag
array_pop($e);
// Perform basic data sanitization
$e = sanitizeData($e);
// Add a content type header to ensure proper execution
header('Content-Type: application/rss+xml');
// Output the XML declaration
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
?>
<rss version="2.0">
<channel>
<title>My Simple Blog</title>
<link>http://localhost/simple_blog/</link>
<description>This blog is awesome.</description>
<language>en-us</language>
<?php
// Loop through the entries and generate RSS items
foreach($e as $e):
// Escape HTML to avoid errors
$entry = htmlentities($e['entry']);
// Build the full URL to the entry
$url = 'http://localhost/simple_blog/blog/' . $e['url'];
?>
<item>
<title><?php echo $e['title']; ?></title>
<description><?php echo $entry; ?></description>
<link><?php echo $url; ?></link>
</item>
<?php endforeach; ?>
</channel>
</rss>
I have explained in form of comments in the code what problems I am facing. Please let me know if I am connecting correctly.
Am I missing something with respect to code or Syntax using xml in php?