I need an RSS feed made for a site built in php and mysql. the website is in russian and I believe the database stores articles in latin1 encoding. You'll have to make sure the title and descrition of the rss feed, and individual items display properly across all major browsers (ie, sefari, firefox, opera).
## Deliverables
I will include the php code I've written so far exept for the db connection info:
The problem I was having originally was that the article text and title looked like this: ?????? ?1 ?? ????? "??????? ? ??"
Then I put this in the header: header("Content-Type: text/xml; charset=windows-1251");. most importantly was the "charset=windows-1251".
This made the articles look almost fine, but the russian text that I hardcoded ended up looking like the articles looked before. In addition, whenever there are double quotes in the body of the article, it looks like so: \". A backslash to escape the quote. Not good.
I give up, Somebody fix this darn thing.
let me know what else you need (export of the db etc...)
<?php
// PHP file that renders perfect Dynamic XML for MySQL Database result sets
// Script written by Adam Khoury @ [login to view URL] - April 05, 2010
// View the video that is tied to this script for maximum understanding
// -------------------------------------------------------------------
header("Content-Type: text/xml; charset=windows-1251"); //set the content type to xml
header("Content-Language: 'ru'");
// Initialize the xmlOutput variable
$xmlBody = '
<rss version="2.0">
<channel>
<title>????????? ???</title>
<description>$desc</description>
<link>[login to view URL]</link>
<copyright>???? ????? ????????. ??????????? ?????????? ?????? ?? ???????????? ? ?????????.</copyright>';
// Connect to your MySQL database whatever way you like to here
mysql_connect("localhost","db_user","db_pass") or die (mysql_error());
mysql_select_db("sinaius2_em") or die ("no database");
// Execute the Query on the database to select items(20 in this example)
mysql_query("SET NAMES latin1");
$sql = mysql_query("SELECT `id`, `title`, `article_text`, `article_date` FROM `articles`ORDER BY `article_date` DESC LIMIT 0 , 15");
while($row = mysql_fetch_array($sql)){
// Set DB variables into local variables for easier use
$id = $row["id"];
$title = $row["title"] ;
$date_time = strftime("%b %d, %Y", strtotime($row["article_date"]));
$description = $row["article_text"];
// Start filling the $xmlBody variable with looping content here inside the while loop
// It will loop through 20 items from the database and render into XML format
$xmlBody .= "
<item>
<title>$title</title>
<description><![CDATA[$description]]></description>
<pubDate>$date_time</pubDate>
<link>[login to view URL]$id</link>
</item> ";
} // End while loop
mysql_close(); // close the mysql database connection_aborted
$xmlBody .= "</channel>
</rss>";
print "<";
print "?xml version=\"1.0\" encoding=\"UTF-8\"?>";
echo $xmlBody; // output the gallery data as XML file for flash
?>