Suite de instructions -> Résoudre un problème
- recherche
- aléatoire
| <?php | |
| $apprenants = ["adora", "mohamad", "berivan", "amare", "zaidi", "suliman", "antoine", "chadi"]; | |
| shuffle($apprenants); | |
| for ($i = 0; $i < count($apprenants); $i = $i + 3) { | |
| echo $apprenants[$i]." ".$apprenants[$i+1]." ".$apprenants[$i+2].'<br />'; | |
| } | |
| ?> |
| <?php | |
| if ($_POST['password'] != "cookie") { // => database | |
| header('Location: form.html'); | |
| } else { | |
| ?> | |
| <!DOCTYPE> | |
| <html> | |
| <head> | |
| <meta charset="utf8" /> | |
| <title>PHP Test</title> |
| <?php | |
| // Connexion à la base de données | |
| try { | |
| $bdd = new PDO('mysql:host=localhost;dbname=test;charset=utf8', 'root', 'simplonco'); | |
| } catch (Exception $e) { | |
| die('Erreur : '.$e->getMessage()); | |
| } | |
| if ($_POST) { |
| <?php | |
| /* | |
| * Open example.json file, | |
| * parse it into a $json array | |
| */ | |
| $string = file_get_contents("example.json", FILE_USE_INCLUDE_PATH); | |
| $json = json_decode($string, true); |
| <?php | |
| $name = "Bob"; | |
| echo $name; | |
| // VS // | |
| echo "Bob"; | |
| // ---------------------------- // |
| <?php | |
| // ##### SECURITY ##### | |
| // Convert potential HTML content contain | |
| // in POST data into HTML Entities | |
| $_POST['pseudo'] = htmlspecialchars($_POST['pseudo']); | |
| ?> | |
| <!DOCTYPE> | |
| <html> | |
| <form method="post" action="#"> | |
| <input type="text" name="pseudo" /> |
| <?php | |
| if ($_POST) { | |
| if (mail($_POST["email"], $_POST["subject"], $_POST ["message"])) { | |
| echo "Sucess: Mail send!"; | |
| } else { | |
| echo "Failure: Mail not send.."; | |
| } | |
| } |
| <?php | |
| class MyClass { | |
| private $myVar = 0; | |
| public function affVar() { | |
| echo "La valeur est:".++$this->myVar; | |
| } | |
| } | |
| $myInstance = new MyClass(); | |
| echo $myInstance->affVar(); // La valeur est : 1 |
| // JS | |
| function max(tab) { | |
| var result = 0; | |
| for (var i = 0; i < tab.length; i++) { | |
| if (tab[i] > result) { | |
| result = tab[i]; | |
| } | |
| } | |
| return result; |