RE: [PHP] Newbie question
| From: | Ford, Mike [LSS] | Date: | Fri, 02 May 2003 10:05:57 +0000 |
| Subject: | RE: [PHP] Newbie question | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-146086@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Justin French [mailto:justin@indent.com.au]
> Sent: 02 May 2003 01:56
>
> on 02/05/03 11:36 AM, Michael Lewis (michael@nichestaffing.com) wrote:
>
> > PHP - <?php if (stristr($_SERVER['HTTP_USER_AGENT'],'MSIE')) :
> > ?>
> > MSIE code
> > <?php elseif
> (stristr($_SERVER['HTTP_USER_AGENT'],'Mozilla/5')) : ?>
> > Mozilla/5 code
> > <?php elseif
> (stristr($_SERVER['HTTP_USER_AGENT'],'Mozilla/4')) : ?>
> > Mozilla/4 code
> > <?php else: ?>
> > Generic code
> > <?php endif; ?>
>
> Try this:
>
> <?
> if (stristr($_SERVER['HTTP_USER_AGENT'],'MSIE'))
> {
> ?>
> MSIE CODE
> <?
> }
> elseif (stristr($_SERVER['HTTP_USER_AGENT'],'Mozilla/5'))
> {
> ?>
> Mozilla/5 code
> <?
> }
> elseif (stristr($_SERVER['HTTP_USER_AGENT'],'Mozilla/4'))
> {
> ?>
> Mozilla/4 code
> <?
> }
> else
> {
> ?>
> Generic Code
> <?
> }
> ?>
>
>
> In other words, the PHP syntax is:
>
> <?
> if(...)
> {
> ...
> }
> elseif(...)
> {
> ...
> }
> else
> {
> ...
> }
> ?>
Justin, that's *a* valid PHP syntax, and presumably your preferred one. The
PHP quoted by the OP is also a valid PHP syntax. Personally, I too much
prefer the : syntax, but prefer to space my php tags out a bit more, so I
would write this as:
PHP -
<?php
if (stristr($_SERVER['HTTP_USER_AGENT'],'MSIE')):
?>
MSIE code
<?php
elseif (stristr($_SERVER['HTTP_USER_AGENT'],'Mozilla/5')):
?>
Mozilla/5 code
<?php
elseif (stristr($_SERVER['HTTP_USER_AGENT'],'Mozilla/4')):
?>
Mozilla/4 code
<?php
else:
?>
Generic code
<?php
endif;
?>
but the end result is the same in any case.
Cheers!
Mike
---------------------------------------------------------------------
Mike Ford, Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS, LS6 3QS, United Kingdom
Email: m.ford@lmu.ac.uk
Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211