0
 <?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?

4

1 回答 1

0

刚刚在黑暗中拍摄

请注意,文件保存为 rss.php

从症状来看,要么是没有保存为 rss.php,要么是服务器上没有安装 PHP。

于 2013-04-28T06:16:40.117 回答