PHP logical operators. There are two problems when determining the file type. The code is as follows:
If ($ type! = 'GIF' | $ type! = 'Jpeg '| $ type! = 'PNG '){
Echo "format error ";
}
Else {
Echo $ type;
}
Question 1: not equal to, yes! =?
Question 2: | it does not work. it is useless to change to or. If you only judge one, it means that it is not correct.
But | why does it not work? if it is in C #, it works absolutely.
Reply to discussion (solution)
1 can be used! = Indicates, you can also use! = Indicates the difference
2. do you mean that if the type is gif, jpeg, or png, the image is correct?
It should be written as follows: if ($ type! = 'GIF' & $ type! = 'Jpeg '& $ type! = 'PNG ')
! = The operator is all equal to '=' in a negative usage. This requires a score, data type, case sensitivity, etc.
Change to this! =.
Question 1: not equal to, yes! =?
! = Is not equal
! = Not all equal
Question 2: | it does not work. it is useless to change to or.
You need to use and & for logical judgment.
Sorry, the logic is incorrect. Sorry for your delay.
Not equal to: <> ,! = ,! =
Here! = Comparison type first
In your context, $ type! = 'GIF' | $ type! = 'Jpeg '| $ type! = 'PNG 'is incorrect
This logical expression indicates that the condition is true if $ type is not equal to one of gif, jpeg, and png.
If $ type = 'gifs 'is set, it must not be jpeg or png.
C # is not true. C # Is it created by a Martian?
Therefore, the expression should be an expression rather than an or expression.
$ Type! = 'GIF' & $ type! = 'Jpeg '& $ type! = 'PNG'