Is there any possible way of echoing PHP from within XML. The reason is because I want to provide an XML feed, and this feed will be dynamic so I will of course need to use PHP to echo out the statements from within the tags. But XML doesn't seem to recognise <?php ?> tags inside it.

I can echo out XML from within PHP but the problem is that when the page is viewed it is read as PHP so none of the tags are shown like they do in usual RSS feeds.

I basically want this...

<item>$item;</item>
<description>$description;</description>

And for it to be displayed on the page like...

<?xml version="1.0"?> 
<rss version="2.0">
<item>Item Content</item>
<description>Description</description>
</rss>

Any ways to do this?

Make it a .PHP file and just include headers to serve the content as XML.

header('content-type: text/xml');

Make it a .PHP file and just include headers to serve the content as XML.

header('content-type: text/xml');

Absolutely brilliant!

This may sound like a stupid question, but if I want to apply xslt to this then I can't just apply it with this being read as an xml file can I?

If that's the reason then it's a bit confusing to me since XSLT is a language which is meant to style XML documents to display them in a presentable format BUT you can only apply it to a html or php generated file, not necessarily XML.

XML is run through a XSLT stylesheet rather than the stylesheet being applied to the XML like you're probably used to with HTML and CSS.

So you'd need a PHP file to create an XSLT processor and to set the stylesheet, XML file and to echo the result.

R.

Got it. Cheers!

Hold on a second... using this means that the file stays a .php file.

Will people be able to use a .php file that generates xml as a possible feed?

Hold on a second... using this means that the file stays a .php file.

Will people be able to use a .php file that generates xml as a possible feed?

Yes
If the output is rss xml, and the headers are set, extension is not significant
rss can be php
html css js ditto
* can be php

it's how they generate all those fake roadsigns kfc signs etc to order

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.