Hi! Could we please enable some services and cookies to improve your experience and our website?

PHPize Online / SQLize Online  /  SQLtest Online

A A A
Login    Share code      Blog   FAQ

Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code

Copy Format Clear

Stuck with a problem? Got Error? Ask AI support!

Copy Clear
Copy Format Clear
<?php <!DOCTYPE html> <html> <body> <form method="post"> 输入数字:<input type="text" name="num" required> <input type="submit" value="判断"> </form> <?php if ($_SERVER["REQUEST_METHOD"] == "POST") { $num = $_POST["num"]; // 验证是否为数字 if (!is_numeric($num)) { echo "错误:请输入有效数字!"; } else { // 转换为整数(自动处理浮点数的整数形式) $integer = (int)$num; // 判断奇偶 echo $integer % 2 == 0 ? "$integer 是偶数" : "$integer 是奇数"; } } ?> </body> </html>
Copy Clear