Page 1 of 1

Adding PHP to my xml file

Posted: Thu Aug 21, 2008 1:42 pm
by vchris
Ok so I have an xml and xsl file. Works great.

How would I make it so users would see my home page as home.php instead of home.xml?
I need to add PHP to my site content, let's say I need to use some variables or better yet connect to a database to display some info, how would I go about doing that?

Re: Adding PHP to my xml file

Posted: Thu Aug 21, 2008 2:19 pm
by jaoudestudios
Have your xml in a .php file and a xml header with the php function header();
i.e.

Code: Select all

 
header("Content-type:text/xml"); // check the exact type!
 
Using the code above will parse your code as xml, this will allow you to do php stuff around your xml code.

Re: Adding PHP to my xml file

Posted: Fri Aug 22, 2008 7:42 am
by vchris
Doesn't seem to be working. The page is blank. Should I be putting echos everywhere?

test.php

Code: Select all

<?php header("Content-type:text/xml"); ?>
<?xml version="1.0" encoding="ISO-8859-1"?>
<note>
  <to>Tove</to>
  <from>Jani</from>
  <heading>Reminder</heading>
  <body>Don't forget me this weekend!</body>
</note>

Re: Adding PHP to my xml file

Posted: Fri Aug 22, 2008 2:27 pm
by jaoudestudios
Yep you will need to echo everything out