question about <<<EOF

View: New views
4 Messages — Rating Filter:   Alert me  

question about <<<EOF

by LKSunny :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello,

i want on inner EOF do something, calculate and call function ? can not ? if
yes, how to ?

<?
echo <<<EOF
some text....
can i calculate on inner EOF ? 10*100 display 1000 ?
can i add function on inner EOF ? date('Y') display 2008 ?
any more text.
EOF;
//i want output is
/*
some text....
can i calculate on inner EOF ? 1000 display 1000 ?
can i add function on inner EOF ? 2008 display 2008 ?
any more text.
*/
?>

Thank You.



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: question about <<<EOF

by Jochem Maas :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

LKSunny schreef:
> Hello,
>
> i want on inner EOF do something, calculate and call function ? can not ? if
> yes, how to ?

no you can't, store the results of calculation and function calls in
variables and use them in the HEREDOC statement.

a HEREDOC declaration is just a string declaration like these:

$s = 'foo';
$t = "bar";

they can't contain expressions, function calls or anything like that.

>
> <?
> echo <<<EOF
> some text....
> can i calculate on inner EOF ? 10*100 display 1000 ?
> can i add function on inner EOF ? date('Y') display 2008 ?
> any more text.
> EOF;
> //i want output is
> /*
> some text....
> can i calculate on inner EOF ? 1000 display 1000 ?
> can i add function on inner EOF ? 2008 display 2008 ?
> any more text.
> */
> ?>
>
> Thank You.
>
>
>


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: question about <<<EOF

by Ross McKay :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tue, 30 Sep 2008 12:48:35 +0800, LKSunny wrote:

>i want on inner EOF do something, calculate and call function ? can not ? if
>yes, how to ?

Same way as you do with "" strings. e.g.

<?php
class foo {
  function bar() {
    return 'world!';
  }

  function hello() {
    echo <<<ENDHELLO
Hello, {$this->bar()}
ENDHELLO;
  }
}

$foo = new foo();
$foo->hello();
?>
--
Ross McKay, Toronto, NSW Australia
"Let the laddie play wi the knife - he'll learn"
- The Wee Book of Calvin

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: question about <<<EOF

by tedd-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

At 12:48 PM +0800 9/30/08, LKSunny wrote:

>Hello,
>
>i want on inner EOF do something, calculate and call function ? can not ? if
>yes, how to ?
>
><?
>echo <<<EOF
>some text....
>can i calculate on inner EOF ? 10*100 display 1000 ?
>can i add function on inner EOF ? date('Y') display 2008 ?
>any more text.
>EOF;
>//i want output is
>/*
>some text....
>can i calculate on inner EOF ? 1000 display 1000 ?
>can i add function on inner EOF ? 2008 display 2008 ?
>any more text.
>*/
>?>


Like I tell my dogs "Don't do it inside".

Place your decision making outside of the herdoc and then branch to
whatever heredoc you want.

My advice,

tedd
--
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

LightInTheBox - Buy quality products at wholesale price!