I'm trying to generate a rss feed xml file output in a file called:
1. my_feed.xml -> doesn't work
2. my_feed.xml.php -> works (kinda)

How can I get the php tags to be recognised so that the code gets parsed as PHP? I'm dynamically pulling data from a database to be output as xml for an RSS feed. I've read several articles and tutorials and they all discuss either reading an existing xml file to be output using PHP or writing a new xml file on the server using PHP. What I'm trying to do is create one on the fly -> Is it possible?
I'm assuming there might be something I need to set up on my server (Apache) - what? I really do not want to use the .php extention for a xml file.

1. As soon as I add php tags anywhere in the document

<?php ?>

they get parsed as <?php ?> and do not go through the php translator.

2. If I use this option I can get a rss feed reader to read my file but can't see nothing in the browser.

Help!

    I think you need to add .xml as a file extension that should be parsed as php.

    Change this line in apaches httpd.conf -

    AddType application/x-httpd-php .php .xml

      Thanks for the tip. added .xml in the httpd.conf file - rebooted the machine.
      Report:
      As soon as I add
      <?xml version="1.0"?>
      as the first line, PHP reports an error on line 1 - obviously because it's trying to parse what's between <? ?> tags.

      Also tried to echo the line out escaping the double quotes (and then the entire body) - no luck - now nothing appears - as if the entire file was .php

      If I try to read it with an rss feed reader it reports: no RSS feed was found at the url.

      Are there any specifications/workarounds tutorials out there explaining this. What is the most common method of aproaching this?

      Thanks!

        instead of <?

        do

        <?php echo "<?"; ?>

        Well, thats what I do anyway, it can't parse the php if its already been parsed _

          Tried that as stated:

          Also tried to echo the line out escaping the double quotes (and then the entire body) - no luck - now nothing appears - as if the entire file was .php

            A more solid (and recommended) solution is to turn short_open_tag off. Then <? won't be recognised as the start of PHP code.

            "<?php" was added back when XML first came out as a replacement for the older (somewhat deprecated) "<?".

              Thanks for the info! You're right - it would make sense to turn the short_open_tag off, however the server I'm using has some older web apps that use older (read:bad) coding and I'm sure things will stop working if I changed this now.
              I'm just thinking right now that perhaps my best option would be to run a nightly cronjob to write the xml file. Or try to cope with the xml.php extention...

                I trialled a web application a while back that had been written half in short tags and half in full tags. I work with short_tags off 'cos I often have XML flying about, so it niggled. I knocked this out to run from the command line - pass it the name of a file: >php foo.php. All I can say about its MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE is that It Worked For Me™

                <?php
                $sr = array(
                	'<?='=>'<? echo',
                	'<?'=>'<?php ',
                	'<?php php'=>'<?php',
                	'<?php xml'=>'<?xml',
                	'<?php  '=>'<?php ');
                
                file_put_contents(
                	$argv[1],
                	str_replace(
                		array_keys($sr),
                		array_values($sr),
                		file_get_contents(
                			$argv[1])));
                ?>

                  Place this inside .htaccess of the directory that you want files with the XML extension to execute as PHP:

                  AddType application/x-httpd-php .xml

                  Then I usally place:

                  header("Content-type: text/xml");

                  as the very first line executed in my script.

                    Write a Reply...