Jump to content


Photo

[Solved] Variables inside of <<<XML XML;


  • Please log in to reply
3 replies to this topic

#1 spongebobusa

spongebobusa
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 24 August 2006 - 06:22 AM

I currently have this:

$xmlDoc =<<<XML
<?xml version="1.0"?>
<AccessRequest xml:lang="en-US">
   <AccessLicenseNumber>123456789</AccessLicenseNumber>
</AccessRequest>
XML;

How can I substitute use a variable inside of a <<<XML XML.  For instance, I want to use $number rather than 123456789.

#2 jwk811

jwk811
  • Members
  • PipPipPip
  • Advanced Member
  • 714 posts

Posted 24 August 2006 - 07:34 AM

<AccessLicenseNumber>123456789</AccessLicenseNumber>

<?php
$number="123456789";
?>
Just add that to the script and I'm pretty sure that would replace the access license number to $number. When you want to use that number just put
<?php
echo $number;
?>
And that number will come up where ever you put it.

Hope that helps!

#3 448191

448191
  • Staff Alumni
  • Advanced Member
  • 3,545 posts
  • LocationNetherlands

Posted 24 August 2006 - 08:06 AM

That won't do it.

This will:
<?php
$licencenumber = 123456789;
$xmlDoc =<<<XML
<?xml version="1.0"?>
<AccessRequest xml:lang="en-US">
   <AccessLicenseNumber>$licencenumber</AccessLicenseNumber>
</AccessRequest>
XML;
?>

Heredoc (<<) will expand vars as if you were using double quotes. Alternitively, you  could look up XML entities.

#4 spongebobusa

spongebobusa
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 24 August 2006 - 04:12 PM

I swear I tried that!  ;D But it now works!  Thanks for the help.

That won't do it.

This will:

<?php
$licencenumber = 123456789;
$xmlDoc =<<<XML
<?xml version="1.0"?>
<AccessRequest xml:lang="en-US">
   <AccessLicenseNumber>$licencenumber</AccessLicenseNumber>
</AccessRequest>
XML;
?>

Heredoc (<<) will expand vars as if you were using double quotes. Alternitively, you  could look up XML entities.






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users