Php rss files

I’ve written the follow php code in a rss.php file.
It works fine, but when I put it on a tool bar, I don’t see the links.
IF I click on the open RSS , all is perfect.
I think it is because I used a php file instead of XML file.
BUT if I put a XML extension then the php doesn’t work.
How do I get around this ?
TIA

Pat

<?php
echo "<?xml version=\\"1.0\\" encoding=\\"iso-8859-1\\"?>";

echo "<rss version=\\"2.0\\">";
echo "<channel>";
	//<!-- title here give the proposed bookmark name -->
echo "<title>zzz RSS</title>";
echo " <link>http://www.zzz.info/rss.php</link>";
echo "   <description>zzz</description>";
echo "   <pubDate> aug, 19 2010 00:12:30 EST </pubDate>";
echo "	<lastBuildDate> aug, 19 2010 00:12:30 EST </lastBuildDate>";
echo "	<ttl> 120 </ttl>";
echo "	<category> newspapers </category>";
echo "	<copyright> Copyright 2004, NotePage, Inc.</copyright>";
echo "	<webMaster> webmaster@notepage.net </webMaster>";
echo "<managingEditor> webmaster@notepage.net </managingEditor>";
echo "before image";
echo "<language>fr</language>";
echo "<image>";
echo "   <title>www.zzz.info</title>";
echo "   <description>Mon Site, tous les événements qui ponctuent le site vie</description>";
echo "<url>http //www.zzz.info/feed-icon-28x28.png</url>";
echo "<link>http //www.zzz.info</link>";
   
echo "</image>";

$typ_art= "and (typ_art= 'Infos' or typ_art= 'Actualites')";
//$typ_art= "and (typ_art = 'Actualites')";

	require_once ('admin/mysql_connect.php'); // Connect to the db.
	$order_by="date_art desc";
		// Make the query. MCC
	$query = "SELECT titre, id_art , typ_art, expire, date_art, message, docs, link FROM info 
		where date_art <= current_date and  expire > current_date " .$typ_art . "
		ORDER BY $order_by "  ;		
	$result = mysql_query ($query); // Run the qery.
	//echo "Result";
	//echo $result;
	$i=0;
	$accents = array("à", "é", "è", "ô", "ù" );
 	$repl_accents = array("a", "e", "e", "o", "u");
	if ($result):
		//echo'<p>&nbsp;</p>';
			while ($row = mysql_fetch_assoc($result)) :
				$exp_date3=explode("-",$row['date_art']);
				$exp_date4= $exp_date3 [2]."-".$exp_date3 [1]."-". $exp_date3 [0];
				$tmp_title= $row['titre'];
				$tmp_title = str_replace($accents, $repl_accents, $tmp_title);
				
				$tmp_title=strtr($tmp_title,'àáâãäçèéêëìíîïñòóôõöùúûüýÿÀÁÂÃÄÇÈÉÊËÌÍÎÏÑÒÓÔÕÖÙÚÛÜÝ',                            'aaaaaceeeeiiiinooooouuuuyyAAAAACEEEEIIIINOOOOOUUUUY');
				
				
				//$tmp_title = mb_convert_encoding( $tmp_title1, "ISO-8859-1", "UTF-8");
				//echo $tmp_title."<br/>";
				$my_title[$i]=$tmp_title ;
				$my_id_art[$i]= $row['id_art'];
				$my_message[$i]=substr($row['message'],0,10);
				$my_date[$i]=$exp_date4;
				$my_id_art[$i]=  $row['id_art'];
				$i+= 1 ;
				//echo "<a href= \\"evenements.php?id_art=". $row['id_art'] . "\\">Lire la suite</a>";
			endwhile; 
		
	else:
		//echo "can't do query ";
	endif;	
		
	

		for ( $counter = 0 ; $counter < $i ; $counter += 1) {
			
			$my_link= "<a href= \\"actualites-pharmaceutiques.php?id_art=". $my_id_art[$counter] . "\\">   " . $my_title[$counter] . "</a>";
			//echo      "<a href= \\"evenements.php?id_art=". $row['id_art'] . "\\">   Lire la suite              </a>";

				echo "<item>";
		   		//echo "<title>".$my_title[$counter]. ". . . id_art = " .$my_id_art[$counter]."</title>";
				//echo "<title>". $my_link ."</title>";
				echo "<description><![CDATA[" . ($my_link) . "]]></description>";
				
				//echo "<title>"."title"."</title>";
		   		//echo "<link>http://www.mozaccycloclub.com/evenements.php?id_art=".$my_id_art[$counter]."</link>";
				//echo "<description>"."description messages "."</description>";
	   			echo "<pubDate>".$my_date[$counter]."</pubDate>";
				echo "</item>";
		};

echo "</channel>";

echo "</rss>";

?>

Got everything working, thanks for the help

I originally had the file with a php extension
http://www.gimra.info/rss.php
and this does exactly what I need.
When I click on the subscribe (s’abonner maintenant) button, the button gets added to the tool bar, but the links are not in the list.
If I click on Open RSS all works great.

Maybe this is coming from my set up ?


for ( $counter = 0 ; $counter < $i ; $counter += 1) {
			
$my_link= "<a href= \\"actualites-pharmaceutiques.php?id_art=". $my_id_art[$counter] . "\\">   " . $my_title[$counter] . "</a>";
echo "<item>";
echo "<description><![CDATA[" . ($my_link) . "]]></description>";
echo "<pubDate>".$my_date[$counter]."</pubDate>";
echo "</item>";
		};

Thanks for the input

OK in the rss.xml file I have found something important, I think.
I changed

echo ‘<’.‘?xml version=“1.0” encoding=“iso-8859-1”?’.‘>’
; and now I don’t get any errors until the last line where I close the php ie ?>

<?php
header('Content-Type: text/xml');
echo '<'.'?xml version="1.0" encoding="iso-8859-1"?'.'>';
echo "<rss version=\\"2.0\\">";

echo "<channel>";
	//<!-- title here give the proposed bookmark name -->
echo "<title>zzzRSS</title>";
echo " <link>http://www.zzz.info/rss.php</link>";
echo "   <description>zzz</description>";

...
?>

Erreur d’analyse XML : aucun élément trouvé NOTHING FOUND
Emplacement : http://www.zzz.info/rss.xml
Numéro de ligne 87, Colonne 3 :?>
–^

It looks like it doesn’t like the closing php

I have :

<?php
header('Content-Type: text/xml');
echo "<?xml version=\\"1.0\\" encoding=\\"iso-8859-1\\"?>";

echo "<rss version=\\"2.0\\">";
echo "<channel>";
	//<!-- title here give the proposed bookmark name -->
echo "<title>Gimra RSS</title>";

But still I don’t get the links in the tool bar button when I subscribe.
(and yes, I delete the tool everytime to make sure I’m properly testing)

But maybe I’m going about this wrong.
If I use a rss.php all seems to work properly except the links in the tool bar button

IF I use a rss.sml file I get

Erreur d’analyse XML : mal formé
Emplacement : http://www.gimra.info/rss.xml
Numéro de ligne 5, Colonne 7 :echo “<rss version=\“2.0\”>”;
------^

It tells me that the row 5 column 7 is mal formed.
echo “<rss version=\“2.0\”>”;

thanks
Pat

PHP is not parsing the file as the web server has not been instructed to parse the file in question as PHP.

If you’re using Apache, you can instruct it to rewrite the rss.xml request to rss.php. thus allowing php to parse the file.

Check out mod_rewrite.

Of course, you can just leave the file extension .php :slight_smile:

http://www.gimra.info/rss.xml

I modified this to avoid this problem

echo ‘<’.‘?xml version=“1.0” encoding=“iso-8859-1”?’.‘>’;

Sounds like a short open tags issue.

The errors you’re getting are in the XML, not the PHP.
Do ‘View Source’ in the browser, and then look at line 87 in that.

My guess is that you might be missing a closing tag somewhere.
I can take a look for you, but zzz.info just shows me a GoDaddy landing page…

Have you send a header telling the client that you’re sending it XML?

Put this at the top of your file:


header('Content-Type: text/xml');