Re: is there anyway to use constants in a string?

From: Date: Tue, 20 Jul 2004 06:28:15 +0000
Subject: Re: is there anyway to use constants in a string?
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-191117@lists.php.net to get a copy of this message
On Tue, 20 Jul 2004 00:31:19 -0400, Jason Barnett <jasbarne@indiana.edu> wrote: > 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)); > > ?> > You don't need the print_r as it's a string. Ugh, sprintf. It's a *lot* slower than using concatenation. Besides which, you don't need that heredoc syntax. Just use quotes. PHP allows you to have a newline in a quoted string. -- DB_DataObject_FormBuilder - The database at your fingertips http://pear.php.net/package/DB_DataObject_FormBuilder paperCrane --Justin Patrin--

« previous php.general (#191117) next »