can someone help me with this error? im trying to make a dynamic rss feed using php.. am i on the right track??

ERROR:
Parse error: syntax error, unexpected T_SL in C:\xampp\htdocs\Gacer\rss.php on line 27

<?php

$output = '<rss version="2.0">	<channel>';

$dbhost = '127.0.0.1';
$dbuser = 'root';
$dbpass = '';

$connect = mysql_connect($dbhost, $dbuser, $dbpass);

if (!$connect){	die('Could not connect: ' . mysql_error());	}

$dbname = 'rss';
mysql_select_db($dbname);

//set the content type to xml
header("Content-Type: text/xml");
	
$sql = mysql_query("SELECT * FROM article LIMIT 10 ORDER BY id DESC");	

?>
	
<title>Name of your site</title>
<description>A description of your site</description>
<link>http://geocities.com/jas_jo679</link>
	
<?php	while($row = mysql_fetch_array($sql)){ 

$output .= <<<EOT	?>
		
<item>
  <title><?php echo strip_tags($row['title']); ?></title>
  <link><?php echo $row['link']; ?></link>
  <description><?php echo htmlentities(strip_tags(substr($row['body'],0,600))); ?> </description>
</item>

<?php
		
EOT;
}
			
$output .= '</channel></rss>';
echo $output;

?>

Recommended Answers

All 7 Replies

I made a dummy xml using my tables.

<?php
header("Content-Type: text/xml");
$output = '<rss version="2.0"><channel>';
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$connect = mysql_connect($dbhost, $dbuser, $dbpass);
if (!$connect) {	
	die('Could not connect: ' . mysql_error());	
}
$dbname = 'test';
mysql_select_db($dbname);
//set the content type to xml
	
$sql = mysql_query("SELECT * FROM content");	
$output .="	
<title> Name of your site </title>
<description> A description of your site </description>";	
while($row = mysql_fetch_array($sql)){ 
	$catname = strip_tags($row['CO_NAME']);
	$link = $row['CO_ANNOUNCE']; 
	$description = htmlentities(strip_tags(substr($row['CO_DESCRIPTION'],0,600)));
	$output .= "	
	<item>
	  <title>$catname</title>
	  <link>$link</link>
	  <description>$description</description>
	</item>";
}			
$output .= '</channel></rss>';
echo $output;
?>

i am really new to rss and i hope i don't annoy you..
i have edited your code with my database and it gives this error when i try to open it with a browser.

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\dummy.php:2) in C:\xampp\htdocs\dummy.php on line 3
A description of your site http://geocities.com/jas_jo679/1.html description1 http://geocities.com/jas_jo679/2.html decription2 http://geocities.com/jas_jo679/3.html description3 http://geocities.com/jas_jo679/4.html description4

thanks for the reply!

Make sure you don't output anything before the header function. Even a whitespace before header can cause this warning.

there are no output before the header..and i don't see any white spaces.. it's very similar to your given code..

<?php
      header("Content-Type: text/xml");
      $output = '<rss version="2.0"><channel>';
      $dbhost = 'localhost';
      $dbuser = 'root';
      $dbpass = '';
      $connect = mysql_connect($dbhost, $dbuser, $dbpass);
      if (!$connect) {
      die('Could not connect: ' . mysql_error());
      }
      $dbname = 'rss';
      mysql_select_db($dbname);
      //set the content type to xml
      $sql = mysql_query("SELECT * FROM article");
      $output .="
      <title> Name of your site </title>
      <description> A description of your site </description>";
      while($row = mysql_fetch_array($sql)){
      $catname = strip_tags($row['title']);
      $link = $row['link'];
      $description = htmlentities(strip_tags(substr($row['body'],0,600)));
      $output .= "
      <item>
      <title>$catname</title>
      <link>$link</link>
      <description>$description</description>
      </item>";
      }
      $output .= '</channel></rss>';
      echo $output;
      ?>

There is one BIG white space before <?php . :)

Try this.

<?php
      header("Content-Type: text/xml");
      $output = '<rss version="2.0"><channel>';
      $dbhost = 'localhost';
      $dbuser = 'root';
      $dbpass = '';
      $connect = mysql_connect($dbhost, $dbuser, $dbpass);
      if (!$connect) {
      die('Could not connect: ' . mysql_error());
      }
      $dbname = 'rss';
      mysql_select_db($dbname);
      //set the content type to xml
      $sql = mysql_query("SELECT * FROM article");
      $output .="
      <title> Name of your site </title>
      <description> A description of your site </description>";
      while($row = mysql_fetch_array($sql)){
      $catname = strip_tags($row['title']);
      $link = $row['link'];
      $description = htmlentities(strip_tags(substr($row['body'],0,600)));
      $output .= "
      <item>
      <title>$catname</title>
      <link>$link</link>
      <description>$description</description>
      </item>";
      }
      $output .= '</channel></rss>';
      echo $output;
      ?>

now the web browser says :

This XML file does not appear to have any style information associated with it. The document tree is shown below.
<rss version="2.0">
−
<channel>
<title> Name of your site </title>
<description> A description of your site </description>
−
<item>
<title>Impact of the Financial Crisis on South Asia</title>
<link>http://geocities/jas_jo679/1.php</link>
−
<description>
As the crisis unfolds, it is becoming apparent that no country could remain immune. While some countries in South Asia had relatively less exposure to the crisis through adverse effects on capital flows, they remain vulnerable to global economic slowdown through export earnings, remittances, and external financing of infrastructure.
</description>
</item>
−
<item>
<title>Emerging Asian Economies Can Lead Asia�s Recovery</title>
<link>http://geocities/jas_jo679/2.php</link>
−
<description>
This year Asia is suffering from a recession, but next year we should see a recovery, particularly from the emerging economies of Asia, which are trying to put less emphasis on exports and turn to domestic demand, consumption, and investment. With world leaders meeting for the World Economic Forum in Davos, Switzerland this last week, the international community must try to help countries sustain economic growth or it is the most vulnerable that will suffer the most.
</description>
</item>
−
<item>
−
<title>
Three Asian Giants Can Shape Regional and Global Agenda
</title>
<link>http://geocities/jas_jo679/3.php</link>
−
<description>
The relationships between China, India, and Japan are of strategic importance for the global economy. There is therefore some merit in strengthening trilateral dialogue in areas of cooperation such as exchange rate policies and fiscal policies. The three countries may consider starting a structured dialogue, including more information exchanges, more learning from reciprocal experiences, and more collective analysis of issues and solutions.
</description>
</item>
−
<item>
−
<title>
The Changing Financial Environment, Policy Issues, and ADB�s Role in Financial Sector Development
</title>
<link>http://geocities/jas_jo679/4.php</link>
−
<description>
We remain in very tenuous financial times. The fallout from the August 2007 subprime crisis is far from over. Financial market turmoil continues with a vengeance. This week�s turbulence only underlines the urgent need for central banks and regulators to assess the underlying problems and build a cogent and proactive plan of action to better preserve regional financial stability.
</description>
</item>
</channel>
</rss>

i think this is missing..

<atom:link href="http://geocities.com/jas_jo679/" rel="self" type="application/rss+xml" />

i tried placing it under <description> and then the browser says:

Parse error: syntax error, unexpected '<' in C:\xampp\htdocs\Gacer\rss_feed.php on line 18

i hope you still have patience with me.. im really sorry..

No. Its okay.. Even I have little knowledge on rss feeds. :( Maybe someone else could shed some light on this one.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.