var in php 5.3.8

I am developing a user registration form and want to validate a user's email address. However,all the php docs I have read suggest the use of filter_var. My script validates a valid email as invalid. Please post a working script or perhaps guide me through my script. Hers is my script :

     <?php
      if(isset($_POST['email'])== true && empty($_POST['email'])false)
      {
       $email = $_POST['email'];
      }
      if(filter_var($email,FILTER_VALIDATE_EMAIL)) 
      {
       echo"valid email";
      }
      else
      {
      echo"invalid email";
      }
     ?>

if(isset($_POST['email'])== true && empty($_POST['email'])false)

this should be

if(isset($_POST['email']) && !empty($_POST['email']) )

or as @jack you can use just

if (!empty($_POST['email']))

the empty() does implicit isset()


$email = isset($_POST['email']) ? $_POST['email'] : "";
echo(filter_var($email,FILTER_VALIDATE_EMAIL) ? "valid email" : "invalid email");

  if(isset($_POST['email'])== true && empty($_POST['email'])false)
                           ^^^^^^^--redundant               ^^^^^---typo?
链接地址: http://www.djcxy.com/p/16540.html

上一篇: var与regexp验证超出预期

下一篇: var在PHP 5.3.8中