|
Posted by Toby Inkster on 12/20/06 07:43
hihibibihi wrote:
> <?php
> $foo="NO";
> $text=<<<EO
> The variable is named: $foo
> EO;
>
> if (TRUE)
> {
> $foo="YES";
> die($text); //how to get $foo="YES" into $text?
> }
> ?>
As Janwillem said, you're doing things the wrong way around. What I think
you're actually asking for is a way to specify the format of the error
message at the top of the code instead of way down the bottom when the
error actually happens. Here, sprintf() is your friend...
<?php
$foo = 'NO';
define('ERRMSG_FOO', 'Foo is now "%s", so I shall die.');
if (1)
{
$foo = 'YES';
die(sprintf(ERRMSG_FOO, $foo));
}
?>
You don't need to use a constant of course -- you could use:
<?php
$foo = 'NO';
$ERRMSG_FOO = 'Foo is now "%s", so I shall die.';
if (1)
{
$foo = 'YES';
die(sprintf($ERRMSG_FOO, $foo));
}
?>
But assuming the message format is not going to change half-way through
your script, a constant seems more sensible.
--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
[Back to original message]
|