Re: [PHP] if syntax using multiple conditions
Thanks! And, *wow* yes I just did try php2asp. Pretty good translation, although a few things need adjusting, it seems to do a remarkable job. I'll definitely have to play with it some more. :) -Brian -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] if syntax using multiple conditions
Brian Anderson wrote: What is the proper syndax in an if statement for containing multiple conditions? example: if ( condition1 && condition2 ) { dothis; } if ( condition1 && (condition2 || condition3) ) { dothis; } Both are valid. First example will validate if both condition1 and condition2 evaluate to true (they're set, and not null or false, etc.). Second example will validate if condition1 evaluates to true AND EITHER condition2 OR condition3 evaluate to true -- John C. Nichel ÜberGeek KegWorks.com 716.856.9675 [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] if syntax using multiple conditions
On Mon, 13 Sep 2004 11:32:00 -0500, Brian Anderson <[EMAIL PROTECTED]> wrote: > What is the proper syndax in an if statement for containing multiple conditions? > > example: > > if ( condition1 && condition2 ) { > > dothis; > } > > if ( condition1 && (condition2 || condition3) ) { > > dothis; > } Looks good to me. > I am trying to translate this from asp to php: > > If WhichAction = 7 And (InStr(filename, "\") Or InStr(filename, "/") Or > (Left(filename, 1) = chr(32)) Or InStr(filename, "*") Or InStr(filename, "?") Or > InStr(filename, "|") Or InStr(filename, "<") Or InStr(filename, ">") Or > InStr(filename, ":") Or InStr(filename, ) Or InStr(filename, "'")) Then > messages = "Bad filename" > filename = "" > WhichAction = 0 > End If I'd use a regular expression so as to match all those symbols with one command. Check out eregi() or maybe strstr(). -- Greg Donald http://destiney.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] if syntax using multiple conditions
Brian Anderson wrote: What is the proper syndax in an if statement for containing multiple conditions? both examples you have given are valid but their logic is slightly different. example: if ( condition1 && condition2 ) { dothis; } if ( condition1 && (condition2 || condition3) ) { dothis; } I am trying to translate this from asp to php: how about using the asp2php program? -- Raditha Dissanayake. http://www.radinks.com/sftp/ | http://www.raditha.com/megaupload Lean and mean Secure FTP applet with | Mega Upload - PHP file uploader Graphical User Inteface. Just 128 KB | with progress bar. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] if syntax using multiple conditions
What is the proper syndax in an if statement for containing multiple conditions? example: if ( condition1 && condition2 ) { dothis; } if ( condition1 && (condition2 || condition3) ) { dothis; } I am trying to translate this from asp to php: If WhichAction = 7 And (InStr(filename, "\") Or InStr(filename, "/") Or (Left(filename, 1) = chr(32)) Or InStr(filename, "*") Or InStr(filename, "?") Or InStr(filename, "|") Or InStr(filename, "<") Or InStr(filename, ">") Or InStr(filename, ":") Or InStr(filename, ) Or InStr(filename, "'")) Then messages = "Bad filename" filename = "" WhichAction = 0 End If -Brian
Re: [PHP] if syntax
Martin Clifford wrote: > There are no brackets necessary if you only have one line of code to be executed in >the case. For example: > > if($var == 1) > echo "Var equals 1"; > } else { > echo Var does not equal 1"; > } This will certianly give a parse error, your sample should be: if ($var == 1) echo "Var equals 1"; else echo "Var does not equal 1"; > > But this is not valid: > > if($var == 1) > echo "Var equals "; > echo "1"; > } else { > > } Again, the sample should look like (but ofcourse this one does not work): if ($var == 1) echo "Var equals "; echo "1"; else echo "Var does not equal 1"; > > HTH > > Martin > > "Alexander Ross" <[EMAIL PROTECTED]> 07/10/02 10:25AM >>> >>> > I know this is correct: > > if ($something) > { > ... > } > else > { > ... > } > > But I recently saw someone use this instead: > > if($something): > ... > else: > ... > > Is that also correct?? No brackets needed? > > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] if syntax
Hmm. I should read a bit further myself! I did not know about the colon indicating that there can be many statements before "else" or "endif". I've learnt something as a result, thanks. I should do some more engaging brain before keyboard! Chris Chris Hewitt wrote: > --snip > (I assume the colon after the "$condition):" is a typo. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] if syntax
Alexander, The thing to do is to try it yourself. Yes its OK for single statements (I assume the colon after the "$condition):" is a typo. The first two examples in the manual (Chapter 11, if) show this syntax though not with "else". HTH Chris Alexander Ross wrote: > >if($something): > ... >else: >... > >Is that also correct?? No brackets needed? > > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] if syntax
OK... This is another easy question that everyone has an answer for. Here's mine :D the if statement has many ways of being formed. 1 line code: (Echo or exit command) if(empty($Variable)) exit; else echo "Variable exists Multiple line code: if(empty($Variable)) { header("Location: Here.com"); exit; } else { echo "Valid variable"; eixt; } Combined: if(empty($Variable)) echo "Variable empty"; else { Header("Location: Here.com"); exit; } or the other alternative (empty($Variable)) ? echo "Empty" : echo "Contains Something"; <[EMAIL PROTECTED]> wrote in message news:OFF48BDDD0.BCC82414-ON87256BF2.004F65C2-87256BF2.004F6811@blackhillscor p.com... > This will only work if you have a single line of code after the else and > if. At least that is my understanding of all languages :) > > J > > > > > > "Alexander Ross" <[EMAIL PROTECTED]> > 07/10/2002 08:25 AM > > > To: [EMAIL PROTECTED] > cc: > Subject:[PHP] if syntax > > > I know this is correct: > > if ($something) > { > ... > } > else > { > ... > } > > But I recently saw someone use this instead: > > if($something): > ... > else: > ... > > Is that also correct?? No brackets needed? > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] if syntax
read here for the alternative control structures in php http://www.php.net/manual/en/control-structures.alternative-syntax.php - Original Message - From: <[EMAIL PROTECTED]> To: "Alexander Ross" <[EMAIL PROTECTED]> Cc: <[EMAIL PROTECTED]> Sent: Wednesday, July 10, 2002 7:28 AM Subject: Re: [PHP] if syntax > This will only work if you have a single line of code after the else and > if. At least that is my understanding of all languages :) > > J > > > > > > "Alexander Ross" <[EMAIL PROTECTED]> > 07/10/2002 08:25 AM > > > To: [EMAIL PROTECTED] > cc: > Subject:[PHP] if syntax > > > I know this is correct: > > if ($something) > { > ... > } > else > { > ... > } > > But I recently saw someone use this instead: > > if($something): > ... > else: > ... > > Is that also correct?? No brackets needed? > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] if syntax
There are no brackets necessary if you only have one line of code to be executed in the case. For example: if($var == 1) echo "Var equals 1"; } else { echo Var does not equal 1"; } But this is not valid: if($var == 1) echo "Var equals "; echo "1"; } else { } HTH Martin >>> "Alexander Ross" <[EMAIL PROTECTED]> 07/10/02 10:25AM >>> I know this is correct: if ($something) { ... } else { ... } But I recently saw someone use this instead: if($something): ... else: ... Is that also correct?? No brackets needed? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] if syntax
This will only work if you have a single line of code after the else and if. At least that is my understanding of all languages :) J "Alexander Ross" <[EMAIL PROTECTED]> 07/10/2002 08:25 AM To: [EMAIL PROTECTED] cc: Subject: [PHP] if syntax I know this is correct: if ($something) { ... } else { ... } But I recently saw someone use this instead: if($something): ... else: ... Is that also correct?? No brackets needed? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] if syntax
I know this is correct: if ($something) { ... } else { ... } But I recently saw someone use this instead: if($something): ... else: ... Is that also correct?? No brackets needed? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php