05/12/2021 19:09 Exercice PHP Corrigé - Partie 1 - WayToLearnX https://waytolea

05/12/2021 19:09 Exercice PHP Corrigé - Partie 1 - WayToLearnX https://waytolearnx.com/2020/04/exercice-php-corrige-partie-1.html 1/27 Exercice PHP Corrigé Exercice PHP Corrigé – Partie 1 Articles Recommandés Web service À quoi sert un Service Web Les applications professionnelles modernes utilisent diverses plates- formes de programmation pour développer des applications Web. Certaines… WayToLearnX » PHP » Exercice PHP Corrigé » Exercice PHP Corrigé – Partie 1   TUTORIELS  ASTUCES  QCM  DÉFI / EXERCICES  CONN 05/12/2021 19:09 Exercice PHP Corrigé - Partie 1 - WayToLearnX https://waytolearnx.com/2020/04/exercice-php-corrige-partie-1.html 2/27 avril 15, 2020  7 Commentaires challenges de programmation, défi programmation, examen php, exercice dev php, exercice php avance, exercices pratiques php, php exercices corriges, s entrainer en php Avec des exercices corrigés en PHP, vous pratiquerez divers concepts du langage de programmation PHP. Vous commencerez par des exercices PHP de base à des exercices plus avancés. La solution est fournie pour chaque exercice. Vous devez essayer de résoudre chaque problème par vous-même avant de vérifier la solution. Si vous avez des questions concernant chaque problème, nous vous encourageons à les poster sur notre forum. Exercice 1: Écrivez un programme pour afficher le nombre, de 4 à 12 en utilisant la boucle PHP. Vous pouvez utiliser soit la boucle « for » ou « while » Sortie prévue: 4 5 6 7 8 9 10 Architecture Microservices Liste de toutes les commandes CMD sous Windows 10, 8 et 7 Rechercher dans notre site Voir : Les 100 fonctions PHP que vous devez savoir – Partie 1 Recherche    TUTORIELS  ASTUCES  QCM  DÉFI / EXERCICES  CONN 05/12/2021 19:09 Exercice PHP Corrigé - Partie 1 - WayToLearnX https://waytolearnx.com/2020/04/exercice-php-corrige-partie-1.html 3/27 11 12 (0.02 sec) (https://paiza.io/projects/EIDI4aPkRco4b-9eJfdQ9A) Écrivez votre code ici  Main.php () + <?php echo "Écrivez votre code ici" ?> Run (Ctrl-Enter) Output () Input () Text (https://out.paiza.io:443/projects/EIDI4aPkRco4b-9eJfdQ9A/output/output.txt)  1 2 3 4 5 6 Corrigé Solution: 1. <?php   TUTORIELS  ASTUCES  QCM  DÉFI / EXERCICES  CONN 05/12/2021 19:09 Exercice PHP Corrigé - Partie 1 - WayToLearnX https://waytolearnx.com/2020/04/exercice-php-corrige-partie-1.html 4/27 Sortie: 4 5 6 7 8 9 10 11 12 2. 3. $i = 4; 4. while($i <= 12) 5. { 6. echo $i; 7. echo "\n"; 8. 9. $i++; 10. } 11. 12. ?> Voir aussi : Les boucles en PHP   TUTORIELS  ASTUCES  QCM  DÉFI / EXERCICES  CONN 05/12/2021 19:09 Exercice PHP Corrigé - Partie 1 - WayToLearnX https://waytolearnx.com/2020/04/exercice-php-corrige-partie-1.html 5/27 Exercice 2: Écrivez un programme pour afficher des nombres de 10 à 1 en utilisant une fonction récursive. Exemple: 10 9 8 7 6 5 4 3 2 1   TUTORIELS  ASTUCES  QCM  DÉFI / EXERCICES  CONN 05/12/2021 19:10 Exercice PHP Corrigé - Partie 1 - WayToLearnX https://waytolearnx.com/2020/04/exercice-php-corrige-partie-1.html 6/27 Success (https://paiza.io/projects/IatBYkrkCmJ4yNqdV4IJLg) (0.04 sec) (https://paiza.io/projects/IatBYkrkCmJ4yNqdV4IJLg)  Main.php () +  <?php function decrement($n) { // Écrivez votre code ici } decrement(10); ?> Run (Ctrl-Enter) Output () Input () Text  1 2 3 4 5 6 7 8 9 10 11 Corrigé Une fonction récursive est une fonction qui s’appelle elle-même. Le programme suivant, affiche les nombres de 10 à 1 à l’aide d’une fonction récursive. Solution:   TUTORIELS  ASTUCES  QCM  DÉFI / EXERCICES  CONN 05/12/2021 19:10 Exercice PHP Corrigé - Partie 1 - WayToLearnX https://waytolearnx.com/2020/04/exercice-php-corrige-partie-1.html 7/27 Sortie: 10 9 8 7 6 5 4 3 2 1 1. <?php 2. 3. function decrement($n) 4. { 5. if($n > 0) 6. { 7. print("$n\n"); 8. decrement($n - 1); 9. } 10. } 11. decrement(10); 12. 13. 14. ?>   TUTORIELS  ASTUCES  QCM  DÉFI / EXERCICES  CONN 05/12/2021 19:10 Exercice PHP Corrigé - Partie 1 - WayToLearnX https://waytolearnx.com/2020/04/exercice-php-corrige-partie-1.html 8/27 Exercice 3: Écrivez un script PHP, pour vérifier si la page est appelée depuis ‘HTTPS’ ou ‘HTTP’. <?php // Écrivez votre code PHP ici ?> Corrigé HTTPS est une extension du HTTP pour une communication sécurisée sur un réseau informatique et est largement utilisé sur Internet. Dans HTTPS, le protocole de communication est chiffré à l’aide de TLS (Transport Layer Security) ou de son prédécesseur SSL (Secure Sockets Layer). Solution: 1. <?php 2. if (!empty($_SERVER['HTTPS'])) 3. { 4. echo 'HTTPS est utilisé'; 5. } 6. else 7. { 8. echo 'HTTP est utilisé'; 9. } 10. ?>   TUTORIELS  ASTUCES  QCM  DÉFI / EXERCICES  CONN 05/12/2021 19:10 Exercice PHP Corrigé - Partie 1 - WayToLearnX https://waytolearnx.com/2020/04/exercice-php-corrige-partie-1.html 9/27 Exercice 4: Écrivez un script PHP pour rediriger un utilisateur vers une autre page. Exemple: Redirigez l’utilisateur vers https://waytolearnx.com/ <?php // Écrivez votre code ici ?> Voir aussi : Différence entre HTTP et HTTPS Corrigé Solution: 1. <?php 2. 3. header('Location: https://waytolearnx.com/'); 4. 5. ?>   TUTORIELS  ASTUCES  QCM  DÉFI / EXERCICES  CONN 05/12/2021 19:10 Exercice PHP Corrigé - Partie 1 - WayToLearnX https://waytolearnx.com/2020/04/exercice-php-corrige-partie-1.html 10/27 Exercice 5: Écrivez un programme PHP pour supprimer les doublons d’un tableau triée. Exemple: [1, 2, 2, 3, 3, 3, 4, 5, 5] Sortie prévue: [1, 2, 3, 4, 5] Voir aussi : Comment faire une redirection en PHP   TUTORIELS  ASTUCES  QCM  DÉFI / EXERCICES  CONN 05/12/2021 19:10 Exercice PHP Corrigé - Partie 1 - WayToLearnX https://waytolearnx.com/2020/04/exercice-php-corrige-partie-1.html 11/27 (0.02 sec) (https://paiza.io/projects/EIDI4aPkRco4b-9eJfdQ9A) Écrivez votre code ici  Main.php () + <?php echo "Écrivez votre code ici" ?> Run (Ctrl-Enter) Output () Input () Text (https://out.paiza.io:443/projects/EIDI4aPkRco4b-9eJfdQ9A/output/output.txt)  1 2 3 4 5 6 Corrigé Solution: 1. <?php 2. 3. $tab = array(1, 2, 2, 3, 3, 3, 4, 5, 5); 4.   TUTORIELS  ASTUCES  QCM  DÉFI / EXERCICES  CONN 05/12/2021 19:10 Exercice PHP Corrigé - Partie 1 - WayToLearnX https://waytolearnx.com/2020/04/exercice-php-corrige-partie-1.html 12/27 Exercice 6: Écrivez un programme pour calculer la factorielle d’un nombre en utilisant la boucle for en PHP Sortie prévue: La factorielle de 3 est 6 Sortie: Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 ) 5. print_r(array_values(array_unique($tab))); 6. 7. ?> Voir aussi : PHP array_unique()   TUTORIELS  ASTUCES  QCM  DÉFI / EXERCICES  CONN 05/12/2021 19:10 Exercice PHP Corrigé - Partie 1 - WayToLearnX https://waytolearnx.com/2020/04/exercice-php-corrige-partie-1.html 13/27 (0.02 sec) (https://paiza.io/projects/EIDI4aPkRco4b-9eJfdQ9A) Écrivez votre code ici  Main.php () + <?php echo "Écrivez votre code ici" ?> Run (Ctrl-Enter) Output () Input () Text (https://out.paiza.io:443/projects/EIDI4aPkRco4b-9eJfdQ9A/output/output.txt)  1 2 3 4 5 6 Corrigé Solution: 1. <?php 2. 3. $n = 3; 4. $f = 1;   TUTORIELS  ASTUCES  QCM  DÉFI / EXERCICES  CONN 05/12/2021 19:10 Exercice PHP Corrigé - Partie 1 - WayToLearnX https://waytolearnx.com/2020/04/exercice-php-corrige-partie-1.html 14/27 Exercice 7: Écrivez un programme PHP pour trouver la factorielle d’un nombre en utilisant une fonction récursive. Sortie prévue: La factorielle de 3 est 6 Sortie: La factorielle de 3 est 6 5. 6. for ($i=$n; $i>=1; $i--) 7. { 8. $f = $f * $i; 9. } 10. 11. echo "La factorielle de $n est $f"; 12. 13. ?> Voir aussi : Fonction itérative pour factorielle en PHP   TUTORIELS  ASTUCES  QCM  DÉFI / EXERCICES  CONN 05/12/2021 19:10 Exercice PHP Corrigé - Partie 1 - WayToLearnX https://waytolearnx.com/2020/04/exercice-php-corrige-partie-1.html 15/27 (0.02 sec) (https://paiza.io/projects/EIDI4aPkRco4b-9eJfdQ9A) Écrivez votre code ici  Main.php () + <?php echo "Écrivez votre code ici" ?> Run (Ctrl-Enter) Output () Input () Text (https://out.paiza.io:443/projects/EIDI4aPkRco4b-9eJfdQ9A/output/output.txt)  1 2 3 4 5 6 Corrigé Une fonction récursive est une fonction qui s’appelle elle-même. Solution:   TUTORIELS  ASTUCES  QCM  DÉFI / EXERCICES  CONN 05/12/2021 19:10 Exercice PHP Corrigé - Partie 1 - WayToLearnX https://waytolearnx.com/2020/04/exercice-php-corrige-partie-1.html 16/27 Exercice 8: Sortie: La factorielle de 3 est 6 1. <?php 2. 3. function fact($n){ 4. if($n <= 1){ 5. return 1; 6. } 7. else{ 8. return $n * fact($n - 1); 9. } 10. } 11. 12. $n = 3; 13. $f = fact($n); 14. echo "La factorielle de $n est $f"; 15. 16. ?> Voir aussi : Fonction récursive pour factorielle en PHP   TUTORIELS  ASTUCES  QCM  DÉFI / EXERCICES  CONN 05/12/2021 19:10 Exercice PHP Corrigé - Partie 1 - WayToLearnX https://waytolearnx.com/2020/04/exercice-php-corrige-partie-1.html 17/27 Écrivez un programme pour afficher le triangle d’etoile suivant en utilisant une boucle for. Exemple: * ** *** **** ***** ****** ******* ******** ********* **********   TUTORIELS  ASTUCES  QCM  DÉFI / EXERCICES  CONN 05/12/2021 19:10 Exercice PHP Corrigé - Partie 1 - WayToLearnX https://waytolearnx.com/2020/04/exercice-php-corrige-partie-1.html 18/27 (0.02 sec) (https://paiza.io/projects/EIDI4aPkRco4b-9eJfdQ9A) Écrivez votre code ici  Main.php () + <?php echo "Écrivez votre code ici" ?> Run (Ctrl-Enter) Output () Input () Text (https://out.paiza.io:443/projects/EIDI4aPkRco4b-9eJfdQ9A/output/output.txt)  1 2 3 4 5 6 Corrigé Solution: 1. <?php 2. 3. for($ligne = 1; $ligne <= 10; $ligne++) 4. {   TUTORIELS  ASTUCES  QCM  DÉFI / EXERCICES  CONN 05/12/2021 19:10 Exercice PHP Corrigé - Partie 1 - WayToLearnX https://waytolearnx.com/2020/04/exercice-php-corrige-partie-1.html 19/27 Exercice 9: Écrivez un programme PHP pour afficher la table de multiplication jusqu’à 5 * 5. Exemple: Sortie: uploads/s1/ exercice-php-corrige-partie-1-waytolearnx 1 .pdf

  • 36
  • 0
  • 0
Afficher les détails des licences
Licence et utilisation
Gratuit pour un usage personnel Attribution requise
Partager
  • Détails
  • Publié le Dec 19, 2021
  • Catégorie Administration
  • Langue French
  • Taille du fichier 3.3987MB