Re: php equivalent for `command`
| From: | Plutarck | Date: | Wed, 18 Apr 2001 14:12:33 +0000 |
| Subject: | Re: php equivalent for `command` | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-49219@lists.php.net to get a copy of this message | ||
> In the second set of code lines, what I need to do is somehow bracket off
the $test++ so it is evaluated before being echoed.
You need to use the string concantenation operator (a period) to use things
like $test++, else PHP get's confused.
> echo "Value of test: $test++ <BR>";
To get that to work like you want it to, you need only do:
echo 'Value of test: ' . $test++ . ' <BR>';
It's functionally the same, no brackets needed. If you want it to be
evaluated BEFORE it's echoed, you need to use:
echo 'Value of test: ' . ++$test . ' <BR>';
--
Plutarck
Should be working on something...
...but forgot what it was.
""Greig, Euan"" <Euan.Greig@brann.com> wrote in message
news:5CEAD14A5163D211A21B0008C724629401C8D821@ciren-mbx1.BRANN.CO.UK...
> I deliberately gave a simple example, perhaps too simple. I want to
output quite long and complicated strings that may involve evaluated
variables, calls to functions etc. But I also want it to as legible as
possible. But even something simple along the lines I quoted gives me
problems. See the following code and its output
>
> <?php
> $test=1;
> echo $test++ . "<BR>";
> echo $test++ . "<BR>";
>
> $test=1;
> echo "Value of test: $test++ <BR>";
> echo "Value of test: $test++ <BR>";
> ?>
>
> The output:
>
> 1
> 2
> Value of test: 1++
> Value of test: 1++
>
> In the second set of code lines, what I need to do is somehow bracket off
the $test++ so it is evaluated before being echoed.
>
> Euan
>
>
> -----Original Message-----
> From: Jason Brooke [mailto:jason@qgl.org]
> Sent: 18 April 2001 09:46
> To: Greig, Euan; php-general@lists.php.net
> Subject: Re: [PHP] php equivalent for
command
>
>
> echo ++$x;
>
> http://www.php.net/manual/en/language.operators.increment.php
>
>
>
> > > Is there a php equivalent for the use of ` (I think) in Unix/Perl? So
> for example echo "$x++" would first evaluate $x++ and
> then print the
> resulting value.
> > >
> > > Euan Greig
> > > Technical Consultant
> > > BRANN DATA
> > > euan.greig@brann.com
> > > 01285 645997
>
>
>
>
> **************************************************************************
> Any opinions expressed in this email are those of the individual and
> not necessarily the Company. This email and any files transmitted with
> it, including replies and forwarded copies (which may contain alterations)
> subsequently transmitted from the Company, are confidential and solely for
> the use of the intended recipient. If you are not the intended recipient
> or the person responsible for delivering to the intended recipient, be
> advised that you have received this email in error and that any use is
> strictly prohibited.
>
> **************************************************************************
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>