0

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?

Edited by asif49: n/a

3
Contributors
7
Replies
8
Views
5 Years
Discussion Span
Last Post by almostbob
1

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

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

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

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

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.

1

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.

0

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?

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.