Utk*_*noi 1 php if-statement logical-operators
名字和姓氏是从 HTML 表单提交的。
在 PHP 中,我想检查它们的长度是否至少为 3 个字符,最多为 18 个字符。我如何在if else声明中检查它
示例代码如下
$f = $_POST['firstname'];
$l = $_POST['lastname'];
if((strlen($f) < 3 || strlen($f) > 16) && (strlen($l) < 3 || strlen($l) > 16))
{
echo "Firstname and lastname must be between 3 and 16 characters";
exit();
}
Run Code Online (Sandbox Code Playgroud)
它不起作用我做错了什么......
感谢您的帮助,希望您能理解我的问题
if((strlen($f) < 3 || strlen($f) > 16) || (strlen($l) < 3 || strlen($l) > 16))
Run Code Online (Sandbox Code Playgroud)
&&中间替换为||
您所做的只会在两者都无效时引发错误。当其中之一出现时,您想扔掉它。