php and xml (rss)

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
m2babaey
Forum Contributor
Posts: 364
Joined: Sun May 20, 2007 9:26 am

php and xml (rss)

Post 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
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: php and xml (rss)

Post 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
cpetercarter
Forum Contributor
Posts: 474
Joined: Sat Jul 25, 2009 2:00 am

Re: php and xml (rss)

Post by cpetercarter »

Alternatively, you could echo line 12 in php instead of outputting it directly.
Post Reply