[SOLVED] 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
User avatar
PrObLeM
Forum Contributor
Posts: 418
Joined: Sun Mar 07, 2004 2:30 pm
Location: Mesa, AZ
Contact:

[SOLVED] Xml and PHP

Post 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?
Last edited by PrObLeM on Thu Jun 24, 2004 2:04 pm, edited 1 time in total.
penguinboy
Forum Contributor
Posts: 171
Joined: Thu Nov 07, 2002 11:25 am

Post by penguinboy »

Post the script?
redmonkey
Forum Regular
Posts: 836
Joined: Thu Dec 18, 2003 3:58 pm

Post 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??
User avatar
PrObLeM
Forum Contributor
Posts: 418
Joined: Sun Mar 07, 2004 2:30 pm
Location: Mesa, AZ
Contact:

Post 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

&lt;?xml version="1.0"?&gt;
	&lt;rss version="2.0"&gt;
      		&lt;title&gt;PrObLeM's Sp0rklog&lt;/title&gt;
		&lt;description&gt;Rss Feed From www.sp0rk.com&lt;/description&gt;
    		&lt;link&gt;http://www.sp0rk.com/PrObLeM/&lt;/link&gt;
    		&lt;language&gt;en-us&lt;/language&gt;&lt;channel&gt;
			&lt;item&gt;

			&lt;title&gt;Test of news post system&lt;/title&gt;
			&lt;description&gt;Yes sir the news post system works just fine and dandy!&lt;/description&gt;
			&lt;link&gt;http://www.sp0rk.com/PrObLeM/&lt;/link&gt;
			&lt;pubDate&gt;06-23-2004&lt;/pubDate&gt;
			&lt;/item&gt;&lt;/channel&gt;&lt;/rss&gt;
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;
?>
Last edited by PrObLeM on Thu Jun 24, 2004 1:52 pm, edited 1 time in total.
penguinboy
Forum Contributor
Posts: 171
Joined: Thu Nov 07, 2002 11:25 am

Post 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.
User avatar
PrObLeM
Forum Contributor
Posts: 418
Joined: Sun Mar 07, 2004 2:30 pm
Location: Mesa, AZ
Contact:

Post 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
User avatar
PrObLeM
Forum Contributor
Posts: 418
Joined: Sun Mar 07, 2004 2:30 pm
Location: Mesa, AZ
Contact:

Post by PrObLeM »

SOLVED!! needed header('Content-type: text/xml');
Post Reply