Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[PHP] Is this kind of code safe?

0 views
Skip to first unread message

Greig, Euan

unread,
Apr 17, 2001, 7:33:30 AM4/17/01
to
I was playing around with various ways of doing conditional output of text, and I tried the following.

<?php
$test="b";
if ($test=="a"):
?>
value is a
<?php
else:
?>
value is not a
<?php
endif;
?>

It seems to work, ie it outputs different text depending on the value of $test. But is it safe, can I rely on this behaviour? Maybe I just missed something somewhere, but I thought I would have to use echo or print in such circumstances. It'll be nice if I was wrong.

Euan Greig
Technical Consultant
BRANN DATA
euan....@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...@lists.php.net
For additional commands, e-mail: php-gene...@lists.php.net
To contact the list administrators, e-mail: php-lis...@lists.php.net

Greig, Euan

unread,
Apr 17, 2001, 7:47:59 AM4/17/01
to
Thanks for that Jason (and so quick!). I agree it's ugly, but I can see it being useful occasionally.

Euan

-----Original Message-----
From: Jason Murray [mailto:Jason....@melbourneit.com.au]
Sent: 17 April 2001 12:38
To: 'Greig, Euan'; php-g...@lists.php.net
Subject: RE: [PHP] Is this kind of code safe?


> <?php
> $test="b";
> if ($test=="a"):
> ?>
> value is a
> <?php
> else:
> ?>
> value is not a
> <?php
> endif;
> ?>
>
> It seems to work, ie it outputs different text depending on
> the value of $test. But is it safe, can I rely on this
> behaviour?

Yes can rely on it, but I just think it's somewhat ugly. If I'm combing
through a file looking for outputs, stepping through multiple ?> and <?php
tags is very annoying.

Jason

Plutarck

unread,
Apr 17, 2001, 10:16:50 AM4/17/01
to
Don't use that on such small outputs, simply for the reason that it's really
hard to read and follow. It also screws up Syntax highlighting.

However, it works just like you would hope it would. When you call an ending
tag, PHP just outputs whatever is there without parsing it. But it doesn't
forget what it was doing, and will pick up right where it left off once you
call an opening tag.

But it can be pretty useful so you don't have to use here-doc printing, or
escape a bunch of things inside of a string.


--
Plutarck
Should be working on something...
...but forgot what it was.


""Greig, Euan"" <Euan....@brann.com> wrote in message
news:5CEAD14A5163D211A21B...@ciren-mbx1.BRANN.CO.UK...

Jason Murray

unread,
Apr 17, 2001, 7:36:32 AM4/17/01
to
> <?php
> $test="b";
> if ($test=="a"):
> ?>
> value is a
> <?php
> else:
> ?>
> value is not a
> <?php
> endif;
> ?>
>
> It seems to work, ie it outputs different text depending on
> the value of $test. But is it safe, can I rely on this
> behaviour?

Yes can rely on it, but I just think it's somewhat ugly. If I'm combing
through a file looking for outputs, stepping through multiple ?> and <?php
tags is very annoying.

Jason

--

0 new messages