Page 1 of 1
[SOLVED] Xml and PHP
Posted: Thu Jun 24, 2004 10:37 am
by PrObLeM
Im trying to make a dynamic rss feed for my site the only problem is that my hosting company wont turn off short tags so i can do so.
The reason i need short tags off is because of the 1st line of xml has <? and ?>
ive tried so many ways to fix it i even email my host to turn them off but they said no... Any Suggestions?
Posted: Thu Jun 24, 2004 10:49 am
by penguinboy
Post the script?
Posted: Thu Jun 24, 2004 10:53 am
by redmonkey
Just echo the tags...e.g....
Code: Select all
echo "<?xml version="1.0" encoding="iso-8859-1"?>\n";
The PHP bbcode tags are screwing with the backslashes??
Posted: Thu Jun 24, 2004 10:58 am
by PrObLeM
the file is rssfeed.php and it gets the username from the folder its being called in.
When i run the script it outputs this (right-click view source)
Code: Select all
<?xml version="1.0"?>
<rss version="2.0">
<title>PrObLeM's Sp0rklog</title>
<description>Rss Feed From www.sp0rk.com</description>
<link>http://www.sp0rk.com/PrObLeM/</link>
<language>en-us</language><channel>
<item>
<title>Test of news post system</title>
<description>Yes sir the news post system works just fine and dandy!</description>
<link>http://www.sp0rk.com/PrObLeM/</link>
<pubDate>06-23-2004</pubDate>
</item></channel></rss>
output to browser
Code: Select all
Rss Feed From www.sp0rk.com http://www.sp0rk.com/PrObLeM/ en-us Yes sir the news post system works just fine and dandy! http://www.sp0rk.com/PrObLeM/ 06-23-2004
It just doest start xml
Code: Select all
<?php
//Includes
include('config.php');
include('classes/db.class.php');
include('classes/error.class.php');
include('classes/template.class.php');
//Objects
//Error
$error = new Error();
//Database
$db = new DataConn($config['dbuname'], $config['dbpass'], $config['dbhost'], $config['dbname']);
//Get Symbolic Link Name
if (eregi('.php', $PHP_SELF))
{
$u_name = explode('/', dirname(substr($PHP_SELF, 0, strpos($PHP_SELF, '.ph'))));
$username = $u_name[(sizeof($u_name)-1)];
}
else
{
$u_name = explode('/', $PHP_SELF);
$username = $u_name[(sizeof($u_name)-2)];
}
$oPut .='<?xml version="1.0"?>
<rss version="2.0">
<title>'.$username.'''s Sp0rklog</title>
<description>Rss Feed From http://www.sp0rk.com</description>
<link>http://www.sp0rk.com/'.$username.'/</link>
<language>en-us</language><channel>';
//////////////////////////////////////////////////////////////////
//Get news
//table = $id_post
$table = $db->oneData("SELECT id FROM users WHERE username='".$username."'") . '_post';
$commenttable = $db->oneData("SELECT id FROM users WHERE username='".$username."'") . '_comments';
$arrayId = explode(',', $db->listTable('id', $table . ' ORDER BY id DESC'));
foreach($arrayId as $id)
{
$postArray = $db->oneAssocArray("SELECT id, subject, dt, body FROM ".$table." WHERE id='".$id."'");
if($postArray['id'] <> '')
{
$oPut .='
<item>
<title>'.$postArray['subject'].'</title>
<description>'.nl2br($postArray['body']).'</description>
<link>http://www.sp0rk.com/'.$username.'/</link>
<pubDate>'. date('m-d-Y', $postArray['dt']). '</pubDate>
</item>';
}
}
$oPut .="</channel></rss>";
echo $oPut;
?>
Posted: Thu Jun 24, 2004 1:04 pm
by penguinboy
PrObLeM wrote:It just doest start xml
What?
You realize xml is a markup language right?
XML doesn't "do" anything other than mark up data.
From your post above everything looks fine.
Posted: Thu Jun 24, 2004 1:51 pm
by PrObLeM
well you know how, when you view xml it is formated and has the color syntax this doesnt i mean sure if you rightclick>view source it it looks like so
Code: Select all
<?xml version="1.0"?>
<rss version="2.0">
<title>PrObLeM's Sp0rklog</title>
<description>Rss Feed From www.sp0rk.com</description>
<link>http://www.sp0rk.com/PrObLeM/</link>
<language>en-us</language><channel>
<item>
<title>Test of news post system</title>
<description>Yes sir the news post system works just fine and dandy!</description>
<link>http://www.sp0rk.com/PrObLeM/</link>
<pubDate>06-23-2004</pubDate>
</item></channel></rss>
but if you just view the page it looks like this
Code: Select all
Rss Feed From www.sp0rk.com http://www.sp0rk.com/PrObLeM/ en-us Yes sir the news post system works just fine and dandy! http://www.sp0rk.com/PrObLeM/ 06-23-2004
Posted: Thu Jun 24, 2004 2:03 pm
by PrObLeM
SOLVED!! needed header('Content-type: text/xml');