<?php
//changing this from whatever it was to UTF-8
header('Content-type: text/xml; charset=utf-8');
//add the library code to make the necessary conversions
include_once("named2hex.inc.php");
//make sure that everything done to strings from now on respects UTF-8
mb_internal_encoding("UTF-8");

//PHP Connect Code for BIB Website

	$user = "admin";
	$pass = "imG8zr0H";
	$db = "rss";
	$connection = mysql_pconnect( "localhost", $user, $pass );
	if ( ! $connection)
	die( "Couldn't connect to MySQL" );
	mysql_select_db( $db, $connection )
	or die ("Couldn't open $db: ".mysql_error() );
	
?>
<rss version="2.0">
<channel>
<title>Business in Berkshire</title>
<description>Business in Berkshire Member News</description>
<link>http://www.businessinberkshire.co.uk/</link>
<copyright>2006 Business in Berkshire</copyright>

<?
$sql = "SELECT id,title,description,link,pubdate FROM feed ORDER by pubdate ASC LIMIT 0,50";
$sql_result = mysql_query($sql); 

if (mysql_num_rows($sql_result) ==0)
{
	die (mysql_error());
}
else {

        while ($row = mysql_fetch_array($sql_result)){
        $id = strip_tags($row['id']);
        $date = $row['pubdate'];
        //apply the conversion to both the title and description
        $title = utf8_encode(named2hex(strip_tags($row['title'])));
        $description = utf8_encode(named2hex(strip_tags($row['description'])));
        //changed this, it was kind of dumb to have the same variable set twice
        //all the second request was doing was truncating the text to 200 chars
        $description = substr($description,0,200);
        
// output to client
//removed htmlentities code below
	
?>

	<item>
	<title><?echo $title;?></title>
	<description><?echo $description;?></description>
	<link><?echo $row[link];?></link> 
	<pubDate><?echo date('D, d M Y H:i:s T',strtotime($date)) ;?></pubDate>
	</item>

<? } }?>

</channel>
</rss>
