Re: is there anyway to use constants in a string?
| From: | Jason Barnett | Date: | Tue, 20 Jul 2004 04:31:19 +0000 |
| Subject: | Re: is there anyway to use constants in a string? | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-191113@lists.php.net to get a copy of this message | ||
I was working on something else tonight when I literally stumbled across another solution that works here... pick your poison:
<?php
$heredoc = <<<XML
<?xml version="1.0" encoding="iso-8859-1" ?>
<root>
<node attribute="I am an attribute">
<text>I am a text node.</text></node> <dynamic>
<string1>%1\$s</string1>
<string1>%1\$s</string1>
<string2>%2\$s</string2>
<integer>%3\$d</integer>
</dynamic>
</root>
XML;
echo '<pre>';
define ('string1', 'Well looky here, some text.');
define ('string2', 'Man, I wish I could be a knight who said nee!');
define ('integer', 123452345.23232);
$xml = sprintf($heredoc, string1, string2, integer);
print_r(htmlentities($xml));
?>