gpt4 book ai didi

php - 将字符数限制在两个限制之间

转载 作者:行者123 更新时间:2023-12-03 08:58:52 25 4
gpt4 key购买 nike

我有一个验证if语句,该语句主要检查两件事。首先:查看名为“why”的下拉框是否为空,如果为空,则会向前端发出错误消息,指出我们需要您提供适当的原因。很好现在,我有第二个条件,即如果出于任何原因,“为什么”下拉框中的值为“其他”,并且如果注释框为空,则将拍摄另一个错误。会说“请在评论框中说明您访问的性质!”

我的问题是我尝试使用它,以便注释框的长度在15到45个字符之间。我一直在努力进行signinpage.php验证大约20个小时,以使其完全符合我的要求,而我却无法到达所需的位置。任何帮助将是可爱的!

if(empty($why)) {
$errors[] = 'Please make sure to select the proper reasoning for your vistit today!';
}
elseif ($why ==='Other' && empty($comments)) {
$errors[] = 'Please explain the nature of your visit in the comments box!';

if (strlen($comments) < 15) {
$errors[] = 'Your explaination is short, please revise!';
}
if(strlen($comments) > 45) {
$errors[] = 'Your explaintion is to long, please revise!';
}
}

缩进:
if(empty($why)) {
$errors[] = 'Please make sure to select the proper reasoning for your vistit today!';
}
elseif ($why ==='Other' && empty($comments)) {
$errors[] = 'Please explain the nature of your visit in the comments box!';

if (strlen($comments) < 15) {
$errors[] = 'Your explaination is short, please revise!';
}
if(strlen($comments) > 45) {
$errors[] = 'Your explaintion is to long, please revise!';
}
}

最佳答案

如果您正确地复制并粘贴了此内容,则说明您的括号弄乱了。将所有注释验证放到一个单独的部分中,只有$why==="Other"才被检查。

if(empty($why))
$errors[] = 'Please make sure to select the proper reasoning for your vistit today!';
elseif ($why ==='Other'){
if(empty($comments))
$errors[] = 'Please explain the nature of your visit in the comments box!';
else{
if (strlen($comments) < 15)
$errors[] = 'Your explaination is short, please revise!';
if(strlen($comments) > 45)
$errors[] = 'Your explaintion is to long, please revise!';
}
}

关于php - 将字符数限制在两个限制之间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14058285/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com