You are here: Re: inclosed variable heredoc « PHP Programming Language « IT news, forums, messages
Re: inclosed variable heredoc

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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация