好的,问题是当我使用修剪功能时不起作用但是当我在没有修剪功能的情况下运行代码时它工作,但不能正常工作(表单接受空格)
<?php
session_start();
unset($_SESSION['username']);
if (isset($_SESSION['username']))
{echo "You are in already";}
else if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
if (!empty(trim($_POST['username'])) && !empty(trim($_POST['email'])))
{
$uname = htmlentities($_POST['username']);
$email = htmlentities($_POST['email']);
$_SESSION['username'] = $uname;
echo "THANKS: " . $uname . "<br />";
}
else { echo "fill the goddemn field"; }
} else { ?>
<form action="index.php" method="post">
<label for="username">USERNAME:</label>
<input type="text" name="username" />
<label for="E-MAIL">E-mail:</label>
<input type="text" name="email" />
<input type="submit" value="Enter" />
</form>
<?php } ?>
我尝试了手册http://php.net/manual/en/function.trim.php但很难阅读,我什么也没弄清楚。