Re: [PHP] is there anyway to use constants in a string?
On Tue, 20 Jul 2004 00:31:19 -0400, Jason Barnett [EMAIL PROTECTED] 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 textI 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-- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] is there anyway to use constants in a string?
On Mon, 19 Jul 2004 10:22:42 -0700, barophobia [EMAIL PROTECTED] wrote: hello. ?php define(MY_CONSTANT, http://google.com/;); $my_string = QQQ MY_CONSTANT: does not work for obvious reasons {MY_CONSTANT}: does not work for obvious reasons {$MY_CONSTANT}: does not work for obvious reasons QQQ; ? $my_string = 'pre'.MY_CONSTANT.'post'; here are my options: 1. assign the constant to a temporary variable and then use that. i.e. $tmp_MY_CONSTANT = MY_CONSTANT; 2. use an array instead of a constant i.e. $config['MY_CONSTANT'] = http://google.com/;; 3. find some secret way to work around the above two options and keep my constants. anybody have any ideas to share? chris. p.s. if you don't know the obvious reasons just say so and i (or someone else) will explain. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php !DSPAM:40fc053b159457466720899! -- DB_DataObject_FormBuilder - The database at your fingertips http://pear.php.net/package/DB_DataObject_FormBuilder paperCrane --Justin Patrin-- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] is there anyway to use constants in a string?
On Mon, 19 Jul 2004 11:48:02 -0700, Justin Patrin [EMAIL PROTECTED] wrote: On Mon, 19 Jul 2004 10:22:42 -0700, barophobia [EMAIL PROTECTED] wrote: $my_string = QQQ MY_CONSTANT: does not work for obvious reasons {MY_CONSTANT}: does not work for obvious reasons {$MY_CONSTANT}: does not work for obvious reasons QQQ; $my_string = 'pre'.MY_CONSTANT.'post'; yeah but did you notice in my example i'm using a heredoc? i did that on purpose. :) chris. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] is there anyway to use constants in a string?
Yes, I know. You can't use defined constants within a normal string, so it won't work in a heredoc either: define('FOO', 'bar'); echo show me FOO; You have to use: echo 'show me '.FOO; On Mon, 19 Jul 2004 12:05:40 -0700, barophobia [EMAIL PROTECTED] wrote: On Mon, 19 Jul 2004 11:48:02 -0700, Justin Patrin [EMAIL PROTECTED] wrote: On Mon, 19 Jul 2004 10:22:42 -0700, barophobia [EMAIL PROTECTED] wrote: $my_string = QQQ MY_CONSTANT: does not work for obvious reasons {MY_CONSTANT}: does not work for obvious reasons {$MY_CONSTANT}: does not work for obvious reasons QQQ; $my_string = 'pre'.MY_CONSTANT.'post'; yeah but did you notice in my example i'm using a heredoc? i did that on purpose. :) chris. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php !DSPAM:40fc1eea223154764716344! -- DB_DataObject_FormBuilder - The database at your fingertips http://pear.php.net/package/DB_DataObject_FormBuilder paperCrane --Justin Patrin-- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] is there anyway to use constants in a string?
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 textI 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)); ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php