I want to pass a php variable into xml script.

Essentially what I want to achive is:
var xmlvariable= '$phpvariable';

Is there a simple solution to this?

Many Thanks

Nick

Although I don't know a thing about xml but if it is a client side text language then wouldn't you use the following:

echo "var xmlvariable= '$phpvariable';"

Thanks but I dont think echo is supported in xml.

Here is what I hope to achieve:

I want the image source of the image object to point to a php variable. I just dont know how to get xml to recognise the php variable.
So it would go something like this:

var xml_variable= '$php_variable'; //unsure how to code the $php..

myImage['blue'] = new Image();
myImage['blue'].src = xml_variable;

You'll either have to give the xml file a .php extension, or set Apache to parse php in xml files. This can be done with the http.conf file or with a .htaccess file. If you don't have access to the server, .htaccess may be the only way for you to do this.
After setting the server, you'll then be able to make the xml file dynamic by adding the necessary php scripts.

ok say I change the file to a .php extension. How do I write the php variable?
My attempt was:

<?php $imagea= 'http://localhost/personal_trainer_system/images/Bench.jpg'?>;	  

myImage['blue'] = new Image();
myImage['blue'].src = $imagea;

But i can see how this wouldnt work because how would the xml code know what a $variable is.

How would you write this syntax?

Thanks for your help

Nick

peter: I have added a line <meta http-equiv="Content-Type" content="text/xml; charset=utf-8" /> and :

<?php
header('Content-Type: text/xml');
?>

but get the following error:

ML Parsing Error: XML or text declaration not at start of entity
Location: http://localhost/personal_trainer_system/ajax2.php
Line Number 2, Column 7: <?xml version="1.0" encoding="utf-8"?>
------^

Ben: its not liking that variable because the image swapper doesnt respond.

Appreciate the help guys

Nick

Problem solved! Overlooked this part of the script was javascript so applied the following:

<?php $imagea= 'http://localhost/personal_trainer_system/videos/9_shoulder_pressbgifa.gif'?>;

  <script type="text/javascript">

 var imageb = "<?php echo $imagea; ?>";

myImage['blue'].src = imageb;

--------------------------------------------
thanks so much to everyone who posted. Credit to you buddylee for helping with the syntax.

Thanks again,

Nick

This question has already been answered. Start a new discussion instead.