Adding PHP to my xml file

XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).

Moderator: General Moderators

Post Reply
vchris
Forum Contributor
Posts: 204
Joined: Tue Aug 30, 2005 7:53 pm
Location: Canada, Quebec

Adding PHP to my xml file

Post 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?
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: Adding PHP to my xml file

Post 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.
vchris
Forum Contributor
Posts: 204
Joined: Tue Aug 30, 2005 7:53 pm
Location: Canada, Quebec

Re: Adding PHP to my xml file

Post 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>
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: Adding PHP to my xml file

Post by jaoudestudios »

Yep you will need to echo everything out
Post Reply