PHP strlen question

前端 未结 5 1933
滥情空心
滥情空心 2021-01-23 03:14

Ok I am checking that a string is at least 4 characters long and 25 or less characters short

I tried to use strlen like this

$userNameSignupLength = strl         


        
5条回答
  •  不知归路
    2021-01-23 03:54

    Using strlen is correct to check the length of a string (in bytes). But a number cannot be both smaller than 4 and greater than 25 at the same time. Use || instead:

    if ($userNameSignupLength < 4 || $userNameSignupLength > 25)
    

    Now the condition is fulfilled if the number is either smaller than 4 or greater than 25.

提交回复
热议问题