Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!doctype html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>ex_03_07</title>
- <?php
- $tCourriels = array(10);
- $tCourriels[0] = "helloKitty23@hotmail.com";
- $tCourriels[1] = "vbeland,69@gmail.com";
- $tCourriels[2] = "vincent@gmail";
- $tCourriels[3] = "vingt;23@gmail.com";
- $tCourriels[4] = "vince";
- $tCourriels[5] = "allo 123@gmail.com";
- $tCourriels[6] = "coucouc@@@hotmail.com";
- $tCourriels[7] = "firstname.lastname@example.com";
- $tCourriels[8] = "email@example.com";
- $tCourriels[9] = "email@example.";
- $infoPersonne = array();
- $infoPersonne["prenom0"] = "hello";
- $infoPersonne["nom0"] = "Kitty";
- $infoPersonne["courriel0"] = $tCourriels[0];
- $infoPersonne = array();
- $infoPersonne["prenom1"] = "Jim";
- $infoPersonne["nom1"] = "Boy";
- $infoPersonne["courriel1"] = $tCourriels[1];
- $infoPersonne = array();
- $infoPersonne["prenom2"] = "Milie";
- $infoPersonne["nom2"] = "LaSouris";
- $infoPersonne["courriel2"] = $tCourriels[2];
- $infoPersonne = array();
- $infoPersonne["prenom3"] = "Coco";
- $infoPersonne["nom3"] = "Carpen";
- $infoPersonne["courriel3"] = $tCourriels[3];
- $infoPersonne = array();
- $infoPersonne["prenom4"] = "Vince";
- $infoPersonne["nom4"] = "Bel";
- $infoPersonne["courriel4"] = $tCourriels[4];
- $infoPersonne = array();
- $infoPersonne["prenom5"] = "Abraham";
- $infoPersonne["nom5"] = "Lincoln";
- $infoPersonne["courriel5"] = $tCourriels[5];
- $infoPersonne = array();
- $infoPersonne["prenom6"] = "George";
- $infoPersonne["nom6"] = "Washington";
- $infoPersonne["courriel6"] = $tCourriels[6];
- $infoPersonne = array();
- $infoPersonne["prenom7"] = "Wilson";
- $infoPersonne["nom7"] = "Woodrow";
- $infoPersonne["courriel7"] = $tCourriels[7];
- $infoPersonne = array();
- $infoPersonne["prenom8"] = "Barack";
- $infoPersonne["nom8"] = "Obama";
- $infoPersonne["courriel8"] = $tCourriels[8];
- $infoPersonne = array();
- $infoPersonne["prenom9"] = "George";
- $infoPersonne["nom9"] = "Bush";
- $infoPersonne["courriel9"] = $tCourriels[9];
- function validerCourriel($unCourriel)
- {
- $codeErreur = 0; //0 = courriel valide
- $positionAt = null;
- $finCourriel = null;
- $codeErreur = verifierCarSpeciaux($unCourriel);
- if ($codeErreur == 0)
- {
- $codeErreur = verifierAt($unCourriel);
- if ($codeErreur == 0)
- {
- $positionAt = $unCourriel . strrpos($unCourriel, "@");
- $finCourriel = substr($unCourriel, $positionAt + 1);
- $codeErreur = verifierPoint($finCourriel);
- if ($codeErreur == 0)
- {
- $codeErreur = verifierFin($finCourriel);
- }
- }
- }
- return $codeErreur;
- }
- function verifierCarSpeciaux($unCourriel)
- {
- $codeErreur = 0;
- $carSpeciaux = array("/",":",",",";"," ","?");
- $cpt = null;
- for ($cpt = 0; $cpt < count($carSpeciaux) && $codeErreur == 0;$cpt++)
- {
- if (strpos($unCourriel, $carSpeciaux[$cpt]) != false)
- {
- $codeErreur = 1;
- }
- }
- return $codeErreur;
- }
- function verifierAt($unCourriel)
- {
- $codeErreur = 0;
- $posAt = strpos($unCourriel, "@");
- if ($posAt > 0)
- {
- if (strpos($unCourriel, "@", $posAt +1) != false)
- {
- $codeErreur = 2;
- }
- }
- else
- {
- $codeErreur = 2;
- }
- return $codeErreur;
- }
- function verifierPoint($finCourriel)
- {
- $codeErreur = 0;
- if (strpos($finCourriel, ".") <= 0)
- {
- $codeErreur = 3;
- }
- return $codeErreur;
- }
- function verifierFin($finCourriel)
- {
- $codeErreur = 0;
- $chaineFin = substr($finCourriel, strpos($finCourriel, "."), strlen($finCourriel));
- if (strlen($chaineFin) < 2)
- {
- $codeErreur = 4;
- }
- return $codeErreur;
- }
- ?>
- </head>
- <body>
- <table bordel="1" bordercolor="#000000">
- <tr>
- <th>Prénom</th>
- <th>Nom</th>
- <th>E-mail</th>
- <th>Codes d'erreurs</th>
- </tr>
- <?php
- for($cpt = 0; $cpt < count($tCourriels); $cpt++)
- {
- echo "<tr>" . "<td>" . $infoPersonne["prenom" . $cpt] . "</td>" . "<td>" . $infoPersonne["nom" . $cpt] . "</td>" . "<td>" . $infoPersonne["courriel" . $cpt] . "</td>" . "<td>" . validerCourriel($infoPersonne["courriel" . $cpt]) . "</td>" . "</tr>";
- }
- ?>
- </table>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement