Advertisement
Guest User

Untitled

a guest
Sep 15th, 2015
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.95 KB | None | 0 0
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>ex_03_07</title>
  6. <?php
  7. $tCourriels = array(10);
  8. $tCourriels[0] = "helloKitty23@hotmail.com";
  9. $tCourriels[1] = "vbeland,69@gmail.com";
  10. $tCourriels[2] = "vincent@gmail";
  11. $tCourriels[3] = "vingt;23@gmail.com";
  12. $tCourriels[4] = "vince";
  13. $tCourriels[5] = "allo 123@gmail.com";
  14. $tCourriels[6] = "coucouc@@@hotmail.com";
  15. $tCourriels[7] = "firstname.lastname@example.com";
  16. $tCourriels[8] = "email@example.com";
  17. $tCourriels[9] = "email@example.";
  18.  
  19. $infoPersonne = array();
  20. $infoPersonne["prenom0"] = "hello";
  21. $infoPersonne["nom0"] = "Kitty";
  22. $infoPersonne["courriel0"] = $tCourriels[0];
  23.  
  24. $infoPersonne = array();
  25. $infoPersonne["prenom1"] = "Jim";
  26. $infoPersonne["nom1"] = "Boy";
  27. $infoPersonne["courriel1"] = $tCourriels[1];
  28.  
  29. $infoPersonne = array();
  30. $infoPersonne["prenom2"] = "Milie";
  31. $infoPersonne["nom2"] = "LaSouris";
  32. $infoPersonne["courriel2"] = $tCourriels[2];
  33.  
  34. $infoPersonne = array();
  35. $infoPersonne["prenom3"] = "Coco";
  36. $infoPersonne["nom3"] = "Carpen";
  37. $infoPersonne["courriel3"] = $tCourriels[3];
  38.  
  39. $infoPersonne = array();
  40. $infoPersonne["prenom4"] = "Vince";
  41. $infoPersonne["nom4"] = "Bel";
  42. $infoPersonne["courriel4"] = $tCourriels[4];
  43.  
  44. $infoPersonne = array();
  45. $infoPersonne["prenom5"] = "Abraham";
  46. $infoPersonne["nom5"] = "Lincoln";
  47. $infoPersonne["courriel5"] = $tCourriels[5];
  48.  
  49. $infoPersonne = array();
  50. $infoPersonne["prenom6"] = "George";
  51. $infoPersonne["nom6"] = "Washington";
  52. $infoPersonne["courriel6"] = $tCourriels[6];
  53.  
  54. $infoPersonne = array();
  55. $infoPersonne["prenom7"] = "Wilson";
  56. $infoPersonne["nom7"] = "Woodrow";
  57. $infoPersonne["courriel7"] = $tCourriels[7];
  58. $infoPersonne = array();
  59.  
  60. $infoPersonne["prenom8"] = "Barack";
  61. $infoPersonne["nom8"] = "Obama";
  62. $infoPersonne["courriel8"] = $tCourriels[8];
  63.  
  64. $infoPersonne = array();
  65. $infoPersonne["prenom9"] = "George";
  66. $infoPersonne["nom9"] = "Bush";
  67. $infoPersonne["courriel9"] = $tCourriels[9];
  68.  
  69. function validerCourriel($unCourriel)
  70. {
  71.     $codeErreur = 0; //0 = courriel valide
  72.     $positionAt = null;
  73.     $finCourriel = null;
  74.     $codeErreur = verifierCarSpeciaux($unCourriel);
  75.    
  76.     if ($codeErreur == 0)
  77.     {
  78.         $codeErreur = verifierAt($unCourriel);
  79.         if ($codeErreur == 0)
  80.         {
  81.             $positionAt = $unCourriel . strrpos($unCourriel, "@");
  82.             $finCourriel = substr($unCourriel, $positionAt + 1);
  83.             $codeErreur = verifierPoint($finCourriel);
  84.             if ($codeErreur == 0)
  85.             {
  86.                 $codeErreur = verifierFin($finCourriel);
  87.             }
  88.         }
  89.     }
  90.     return $codeErreur;
  91. }
  92.  
  93. function verifierCarSpeciaux($unCourriel)
  94. {
  95.     $codeErreur = 0;
  96.     $carSpeciaux = array("/",":",",",";"," ","?");
  97.    
  98.     $cpt = null;
  99.     for ($cpt = 0; $cpt < count($carSpeciaux) && $codeErreur == 0;$cpt++)
  100.     {
  101.         if (strpos($unCourriel, $carSpeciaux[$cpt]) != false)
  102.         {
  103.             $codeErreur = 1;       
  104.         }
  105.     }
  106.     return $codeErreur;
  107. }
  108.  
  109. function verifierAt($unCourriel)
  110. {
  111.     $codeErreur = 0;
  112.     $posAt = strpos($unCourriel, "@");
  113.    
  114.     if ($posAt > 0)
  115.     {
  116.         if (strpos($unCourriel, "@", $posAt +1) != false)
  117.         {
  118.             $codeErreur = 2;   
  119.         }
  120.     }
  121.     else
  122.     {
  123.         $codeErreur = 2;   
  124.     }
  125.     return $codeErreur;
  126. }
  127.  
  128.  
  129. function verifierPoint($finCourriel)
  130. {
  131.     $codeErreur = 0;
  132.     if (strpos($finCourriel, ".") <= 0)
  133.     {
  134.         $codeErreur = 3;   
  135.     }
  136.     return $codeErreur;
  137. }
  138.  
  139. function verifierFin($finCourriel)
  140. {
  141.     $codeErreur = 0;
  142.     $chaineFin = substr($finCourriel, strpos($finCourriel, "."), strlen($finCourriel));
  143.     if (strlen($chaineFin) < 2)
  144.     {
  145.         $codeErreur = 4;   
  146.     }
  147.     return $codeErreur;
  148. }
  149. ?>
  150. </head>
  151. <body>
  152. <table bordel="1" bordercolor="#000000">
  153.     <tr>
  154.         <th>Prénom</th>
  155.         <th>Nom</th>
  156.         <th>E-mail</th>
  157.         <th>Codes d'erreurs</th>
  158.     </tr>
  159.  
  160. <?php
  161.     for($cpt = 0; $cpt < count($tCourriels); $cpt++)
  162.     {
  163.         echo "<tr>" . "<td>" .  $infoPersonne["prenom" . $cpt] . "</td>" . "<td>" . $infoPersonne["nom" . $cpt] . "</td>" . "<td>" . $infoPersonne["courriel" . $cpt] . "</td>" . "<td>" . validerCourriel($infoPersonne["courriel" . $cpt]) . "</td>" . "</tr>";
  164.     }      
  165. ?>  
  166. </table>
  167.  
  168.  
  169.  
  170. </body>
  171. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement