XML and PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

XML and PHP

Post by Nay »

Hey, I was getting into the whole XML and PHP thing and I saw this newsfeed on Jason's site and started getting into it. Well, so far I've got this script. It's working fine but I'd like some opinions from the experianced. So anyway:

Code: Select all

<?php

require "templates/config.php";
$config = new config();
$host = $config->mysql_host;
$user = $config->mysql_user;
$pass = $config->mysql_pass;
$data = $config->mysql_data;

$connection = mysql_connect($host, $user, $pass);
$database = mysql_select_db($data, $connection);
$id = $_GET['id'];

header ("Content-type: text/xml");

if(isSet($id) && !empty($id) && is_numeric($id)) {

// feed for a selected article <-- not completed yet

} else {

echo <<< XML
<?xml version="1.0" encoding="ISO-8859-1"?>

<rdf:RDF xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:h="http://www.w3.org/1999/xhtml" xmlns:hr="http://www.w3.org/2000/08/w3c-synd/#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://purl.org/rss/1.0/">

   <channel>
       <title>ChaosDreamers.com News and Updates</title>
       <description>ChaosDreamers.com - Blog, News, Articles, RSS/RDF Feed</description>
       <link>http://www.chaosdreamers.com</link>
   </channel>

   <channel>
XML;

$query2 = "select *, date_format(date, '%d-%m-%y') as for_date from news order by id desc limit 10";
$result2 = mysql_query($query2, $connection) or die(mysql_error());

   while($rows=mysql_fetch_array($result2)) {
   $news = str_replace("\n", "<br />", $rows['news']);
echo <<< ITEM

   <item>
      <title>{$rows['title']}</title>
      <date>{$rows['for_date']}</date>
      <news>$news</news>
   </item>
ITEM;

   }

echo <<< END

   </channel>

</rdf:RDF>
END;

}
?>
Thanks,

-Nay
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post by Gen-ik »

oppps.... sorry.... just passing through....
Post Reply