我试图弄清楚如何应用条件来检查一年是否是闰年。但是当我添加跳跃功能时,它就不起作用了。知道如何让它发挥作用吗?这是我的代码: <?php$name = "";$character = "";$email = "";$birth_year = 1969;$validation_error = "";$existing_users = ["admin", "guest"];$options = ["options" => ["min_range" => 1920, "max_range" => date("Y")]];function leap($year) { date('L', strtotime("$year-01-01")) ? TRUE : FALSE;}if ($_SERVER["REQUEST_METHOD"] == "POST") { $raw_name = trim(htmlspecialchars($_POST["name"])); if (in_Array($raw_name,$existing_users)){ $validation_error .= "This name is taken. <br>"; } else { $name = $raw_name; } $raw_character = $_POST["character"]; if (in_array($raw_character,["wizard", "mage", "orc"])) { $character = $raw_character;} else { $validation_error .= "You must pick a wizard, mage, or orc. <br>"; } $raw_email = $_POST["email"]; if (filter_var($raw_email,FILTER_VALIDATE_EMAIL)) { $email = $raw_email; } else { $validation_error .= "Invalid email. <br>"; } $raw_birth_year = $_POST["birth_year"]; if (filter_var($raw_birth_year,FILTER_VALIDATE_INT,$options)){$birth_year = $raw_birth_year;if ($raw_character === "mage") { if (!leap($birth_year)){ $validation_error .= "Mages have to be born on leap years. <br>"; }}} else { $validation_error .= "That can't be your birth year. <br>";}}?><h1>Create your profile</h1><form method="post" action=""><p>Select a name: <input type="text" name="name" value="<?php echo $name;?>" ></p><p>Select a character: <input type="radio" name="character" value="wizard" <?php echo ($character=='wizard')?'checked':'' ?>> Wizard <input type="radio" name="character" value="mage" <?php echo ($character=='mage')?'checked':'' ?>> Mage <input type="radio" name="character" value="orc" <?php echo ($character=='orc')?'checked':'' ?>> Orc</p><p>Enter an email:<input type="text" name="email" value="<?php echo $email;?>" ></p><p>
1 回答
慕婉清6462132
TA贡献1804条经验 获得超2个赞
我认为你的问题是该函数没有返回任何内容,请尝试:
function leap($year) { return date('L', strtotime("$year-01-01")) ? TRUE : FALSE; }
- 1 回答
- 0 关注
- 92 浏览
添加回答
举报
0/150
提交
取消