1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| <?PHP
ini_set('display_errors', "1");
ini_set('error_reporting', E_ALL ^ E_NOTICE);
header("Content-type: text/xml");
//Connect to Database
include 'dbconnect.php';
$linkID = mysql_connect($db_host, $db_user, $db_pwd) or die("Could not connect to host.");
mysql_select_db($db_name, $linkID) or die("Could not find database.");
$query = "SELECT * FROM photos ORDER BY id_ DESC";
$resultID = mysql_query($query, $linkID) or die("Data not found.");
$xml_output = "<?xml version='1.0' encoding='utf-8'?>\n";
$xml_output .= "<rss>\n";
for($x = 0 ; $x < mysql_num_rows($resultID) ; $x++){
$row = mysql_fetch_assoc($resultID);
$xml_output .= "\t<channel>\n";
// Escaping illegal characters
$row['text'] = str_replace("&", "&", $row['text']);
$row['text'] = str_replace("<", "<", $row['text']);
$row['text'] = str_replace(">", ">", $row['text']);
$row['text'] = str_replace("\"", """, $row['text']);
$xml_output .= "\t\t<id_>" . $row['id_'] . "</id_>\n";
$xml_output .= "\t\t<img>" . $row['img'] . "</img>\n";
$xml_output .= "\t\t<des>" . $row['des'] . "</des>\n";
$xml_output .= "\t\t<link>" . $row['link'] . "</link>\n";
$xml_output .= "\t</channel>\n";
}
$xml_output .= "</rss>";
echo $xml_output;
?> |