Jump to content

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


spongebobusa

Recommended Posts

I currently have this:

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

How can I substitute use a variable inside of a <<<XML XML.  For instance, I want to use $number rather than 123456789.
Link to comment
Share on other sites

<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!
Link to comment
Share on other sites

That won't do it.

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

Heredoc (<<) will expand vars as if you were using double quotes. Alternitively, you  could look up XML entities.
Link to comment
Share on other sites

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

[quote author=448191 link=topic=105448.msg421288#msg421288 date=1156406815]
That won't do it.

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

Heredoc (<<) will expand vars as if you were using double quotes. Alternitively, you  could look up XML entities.
[/quote]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.