title: CLI app in PHP that asks for name and email address in php
body: <p>I am working on creating a PHP CLI basic script that asks for name and email address and validates email and if everything is correct would just print the information.</p>
  
  <p>I have done some basic structure as in code below :</p>
  
  <pre><code>&lt;?php
  echo "Enter your first name : ";
  $firstName = trim(fgets(STDIN));
  echo "Enter your last name : ";
  $lastName = trim(fgets(STDIN));
  echo "Enter your email address : ";
  $email = trim(fgets(STDIN));
  $validEmail = validateEmailAddress($email);
  if(!$validEmail){
      echo "Invalid Email Address";
  }else{
        echo "Welcome $firstName $lastName";
        } 
  
  function validateEmailAddress($email)
  {
      $validEmail = true;    
      $regex = '/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/'; 
      if (!preg_match($regex, $email)) {
       echo "Invalid email address. Please try again.";
       $validEmail = false;
      }          
      return $validEmail;
  }
  ?&gt;
  </code></pre>
  
  <p>Currently the  code stops when I enter an invalid email address, how do I make it interactive, so that if its incorrect it asks user to enter it again until he enters an correct email address.
  The current code starts again to enter the names which is not interactive.</p>
  
  <p>Also, would be great to know the best standards I should follow when creating such application (CLI), would it be better to do it in OOPS way, as this is my uni test.</p>