Advertisement
Guest User

Untitled

a guest
Mar 27th, 2015
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. first,last,username,email
  2. John,Doe,johndoe,John.Doe@email.com
  3. JANE,DOE,JANEDOE,JDOE@EMAIL.COM
  4. Bob,Smith,bobsmith,Bob.Smith@email.com
  5. Bill,Nelson,BILLNELSON,BILL.W.NELSON@EMAIL.COM
  6.  
  7. $csv_row = file($_FILES['csv_file']['tmp_name']);
  8.  
  9. // loop around
  10. if (is_array($csv_row)) {
  11. foreach (array_slice($csv_row,1) as $row) {
  12.  
  13. // split into values
  14. $csv_data = explode(",", $row);
  15.  
  16. // Take forth value $csv_data[3] which is the email
  17. $email = $csv_data[3];
  18.  
  19. //Verify domains
  20. $email_domain = substr(strrchr($email, "@"), 1);
  21. $domains = array('Email.com', 'EMAIL.COM');
  22.  
  23.  
  24. // Validate email format
  25. if ( !is_email( $email ) ) {
  26. echo '<p><code>' . $email . ' is not a valid email.</code></p>';
  27. } else {
  28. echo '<p><code>' . $email . ' is a valid email.</code></p>';
  29. }
  30.  
  31. // Validate email domain
  32. if ( !in_array($email_domain, $domains)) {
  33. echo '<p><code>' . $email_domain . ' is not a valid email domain.</code></p>';
  34. } else {
  35. echo '<p><code>' . $email_domain . ' is a valid email domain.</code></p>';
  36. }
  37. }
  38. }
  39.  
  40. John.Doe@Email.com is not a valid email.
  41. Email.com is not a valid email domain.
  42.  
  43. Jane.Doe@Email.com is not a valid email.
  44. Email.com is not a valid email domain.
  45.  
  46. Bob.Smith@Email.com is not a valid email.
  47. Email.com is not a valid email domain.
  48.  
  49. BILL.W.NELSON@EMAIL.COM is a valid email.
  50. EMAIL.COM is a valid email domain.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement