$var not greater than and not lesser than character length
Can't seem to get this to work. What Im trying to achieve is check if the variable isn't longer than 68, but also not shorter than 64.
However, I can't seem to achieve even that...can someone please point out what I'm doing wrong?
Also, is there a way to simplify this procedure?
if (!strlen($pre_session_key_1) > 68) {
if (!strlen($pre_session_key_1) < 64) {
......
}
}
Thanks and please be kind newb here,
Try:
if (!(strlen($pre_session_key_1) > 68)) {
if (!(strlen($pre_session_key_1) < 64)) {
......
}
}
Or better yet:
if ((strlen($pre_session_key_1) <= 68) &&
(strlen($pre_session_key_1) >= 64))
{
......
}
!strlen($pre_session_key_1) > 68)
^----
you're doing (Not length of string) > 68
You should realize that Not greater
is basically the same as less than or equal to
, so your !>
should be <=
.
你可以尝试这样的事情
$valid=strlen( $pre_session_key_1 )>=64 && strlen( $pre_session_key_1 )<=68;
if( $valid ){ /* do stuff */ }
链接地址: http://www.djcxy.com/p/10038.html
上一篇: “是”运算符的意外行为与整数
下一篇: $ var不大于并且不小于字符长度