Re: If/else conditional statement ... in an include file ...

From: Date: Sun, 23 Dec 2001 20:45:44 +0000
Subject: Re: If/else conditional statement ... in an include file ...
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-78628@lists.php.net to get a copy of this message
I apologize for not including all of the information. I did this as an include file, which explains why it isn't working: < !--- beginning of myinclude.php ---- > <? If ($varA == True) { ?> < ! --- end of myinclude.php --- > < ! ---- beginning of testfile.php --- > <? Include('myinclude.php'); ?> Html here that should display only if $varA == True < ? } // generic parser error generated here Else { ?> HTML that only displays if $varA != True <? } ?> < ! ----- End of testfile.php ---- > In ASP this works, in PHP it doesn't ... any ideas? "Michael Sims" <mhsims@midsouth.rr.com> wrote in message news:5.1.0.14.0.20011223143221.03d66a98@pop-server.midsouth.rr.com... > At 01:11 PM 12/23/2001 -0700, Robert Dyke wrote: > >Hello: > > > >In ASP I can write a Conditional statement like this: > > > ><% If $varA == True Then %> > >Straight HTML in here that only displays if $varA == True > ><% Else %> > >Straight HTML in here that only displays if $varA != True > ><% End if %> > > > >Translating this to PHP doesn't work: > > > ><? If ($varA == True) { ?> // error is generated here ... > > > > > >Is there some way to do it this way in PHP? I'd rather not create a huge > >variable and then echo that. > > As others have pointed out, the above should work provided that you are > terminating your curly braces properly. > > Another (perhaps easier) option would be to use "alternate syntax" which is > more similar to VBScript. For example, the following works in PHP: > > <?if($varA === true):?> > ...html... > <?else:?> > ...html... > <?endif?> > > Note the colon's which are required. The endif will need a semicolon if > there are any other commands after it in the same code block. Also, I > don't believe you can mix alternate syntax and normal syntax in the same > control structure. For example, the following will probably give an error: > > <? > if (condition): > if (other condition) { > do stuff > } > endif; > ?> > > You'd have to use alternate syntax on the nested if statement as well... > > I personally prefer alternate syntax when I'm breaking into and out of PHP > a lot, like the example above. For more info: > > > http://www.php.net/manual/en/control-structures.alternative-syntax.php >

« previous php.general (#78628) next »