This is some code and the data is valid in it.
It's me hours.
But here is the question that they use the statement; Why did they use the exclamation mark (!) Before the filter_var ()
function? This does not make sense to me from a logical point of view, what does the statement ask because I'm pretty sure that the filter_var ()
function is not a boolean
! Filters_ ($ IP, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) === Incorrect) {Echo ("$ IP is a valid IPv6 address"); } Else {echo ("$ ip is not a valid IPv6 address"); }? & Gt; Finally, if the above statement works, because in the first chapters he wrote the following: if (! Filter_var ($ email, FILTER_VALIDATE_EMAIL) )) {$ EmailErr = "Invalid Email Format"; }
that says "if email is not valid, then throw error". However in the code at the top of this question, it says, "If Email No is valid, then incorrect
is coming back and it is === false
. Is not it misleading?
Returns the input value filter_only
if it is valid. A valid IPV6 address is "true" (this is an empty string). !
Operator is applied to a true value false
.
So if $ ip Valid, then
! Filter_var ($ ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) === False
.
Remember !
to High priority ===
This separates two code samples into your code.
filter_var
return False
If the test fails, then it would be a good (and probably obvious) method to test it well:
if (filter_var ($ ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)! == incorrect) {// $ ip is valid}
The second piece of code effectively does the same thing (checking the result filter_var
Is incorrect
), though it does it in a less obvious way.
No comments:
Post a Comment