Page 1 of 1

php and xml (rss)

Posted: Tue Nov 30, 2010 12:07 am
by m2babaey
Hi
I have wrote a code to generate rss feed by a php script
It works fine on localhost, but when uploaded to the server, it sends this error:
Parse error: syntax error, unexpected T_STRING in /path_to_directory/rss_feed.php on line 12
As you see line 12 is:

Code: Select all

<?xml version="1.0" encoding="ISO-8859-1" ?>
This is the script itself:

Code: Select all

<?php
session_start(); 
 require("dbconnect.php"); 
 if(!isset($_SESSION['usertype']))
   { 
   	header("Location: login.php");
	}
else
	{
header("Content-Type: application/xml; charset=ISO-8859-1"); 
?>
<?xml version="1.0" encoding="ISO-8859-1" ?>
<rss version="2.0">

<channel>
  <title>page title</title>
  <link>page link</link>
<?php

$result=mysql_query("SELECT * FROM feed ORDER BY id DESC LIMIT 20 ");
while($row=mysql_fetch_array($result)){

//there are some more code here

$item="<item>
    <title>$title</title>
    <link>$link</link>
    <description>$desc</description>
  </item>";

echo $item;

}

	}
?>
</channel>
</rss>
Thank you very much for your help

Re: php and xml (rss)

Posted: Tue Nov 30, 2010 2:52 am
by Darhazer
Most likely on the server is enabled short_open_tag setting.
You have to disable it when you are embedding XML in your PHP scripts, otherwise <? is treated as PHP opening tag and php code is expected

Re: php and xml (rss)

Posted: Wed Dec 01, 2010 1:19 am
by cpetercarter
Alternatively, you could echo line 12 in php instead of outputting it directly.