Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Syntaxe du langage PHP

4,764 views

Published on

Présentation de la syntaxe de base de PHP

Published in: Technology
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download Full EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download Full doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book THIS can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer THIS is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story THIS Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money THIS the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths THIS Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download Full EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download Full doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book THIS can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer THIS is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story THIS Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money THIS the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths THIS Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download Full EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download Full doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book THIS can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer THIS is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story THIS Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money THIS the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths THIS Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download Full EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download Full doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book THIS can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer THIS is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story THIS Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money THIS the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths THIS Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Syntaxe du langage PHP

  1. 1. Jean-Marie Renouard LightPath 2014©
  2. 2. Le logo PHP est du domaine public http://commons.wikimedia.org/wiki/File:PHP-logo.svg Ce document est licencié sous licence ◦Attribution-NonCommercial-ShareAlike ◦CC BY-NC-SA Plus de détails: http://creativecommons.org/licenses/by-nc-sa/3.0/fr/ LightPath 2014© - http://www.jmrenouard.fr 2
  3. 3. La syntaxe de base Les types Les variables Les constantes Les expressions Les opérateurs 3 LightPath 2014© - http://www.jmrenouard.fr
  4. 4. Les structures de contrôle Les références Les fonctions 4 LightPath 2014© - http://www.jmrenouard.fr
  5. 5. 5 LightPath 2014© - http://www.jmrenouard.fr
  6. 6. Balise de code : ◦<?php ?> ◦<script language="php"> </script> Balise de variable : ◦<?= ?> ◦<?= nom ?> <?= prenom ?> Balise d'expression : ◦<? echo “bonjour” ?> Privilégier les tags PHP suivants: <?php ?> ◦Les tags courts sont déconseillés car non actifs. ◦short_open_tag=1 # Active les shorts tags 6 LightPath 2014© - http://www.jmrenouard.fr
  7. 7. <p>Ceci sera ignoré.</p> <?php echo 'Alors que ceci sera analysé par PHP.'; ?> <p>Ceci sera également ignoré.</p> 7 LightPath 2014© - http://www.jmrenouard.fr
  8. 8. Chaque expression ou commande se termine par un point virgule (;) <?php echo « bonjour »; echo « le monde »; ?> 8 LightPath 2014© - http://www.jmrenouard.fr
  9. 9. Les commentaires type C : ◦Bloc de commentaire sur plusieurs ligne : /* et */ Les commentaires type C++ : ◦Bloc de commentaire uni-ligne : // Les commentaires type shell Unix ou Perl ◦Bloc de commentaire uni-ligne : # 9 LightPath 2014© - http://www.jmrenouard.fr
  10. 10. include ◦Inclus le contenu d'un autre fichier ◦Si il y a du code PHP, il est interprété et executé include_once ◦Le code n'est inclus que la première fois require, require_once : ◦Similaire à include et include_once ◦Produit une erreur fatale au lieu d'une alerte 10 LightPath 2014© - http://www.jmrenouard.fr
  11. 11. 11 LightPath 2014© - http://www.jmrenouard.fr
  12. 12. 4 types scalaires 2 types complexes 2 types spéciaux 3 pseudo-types var_dump() affiche le type et la valeur. gettype() retourne le type d'une variable 12 LightPath 2014© - http://www.jmrenouard.fr
  13. 13. Booléen : 2 valeur vrai ou faux Entier : valeur numérique entière Nombre à virgule flottante Chaîne de caractère 13 LightPath 2014© - http://www.jmrenouard.fr
  14. 14. Les tableaux à index Les tableaux à clé Imbrication des tableaux Les classes Les objets 14 LightPath 2014© - http://www.jmrenouard.fr
  15. 15. Ressource : ◦référence sur un type externe ◦Données produites par certains fonctions NULL : valeur signifiant abscence de valeur ◦Fonctions utilitaires : isset(), is_null() , unset() 15 LightPath 2014© - http://www.jmrenouard.fr
  16. 16. Mixed : une variable acceptant plusieurs types Nombre : entier ou nombre à virgule Callback : nom d'une fonction sous forme de chaîne 16 LightPath 2014© - http://www.jmrenouard.fr
  17. 17. 17 LightPath 2014© - http://www.jmrenouard.fr
  18. 18. Essentiel Variables pré-définies Portée des variables Les variables dynamiques Variables externes à PHP 18 LightPath 2014© - http://www.jmrenouard.fr
  19. 19. Variable : $+Nom de la variable Sensible à la casse ( $a != $A) Spécification d'une variable: [a-zA-Z_x7f- xff][a-zA-Z0-9_x7f-xff]* Pas d'espace de nommage Collision de nom possible 19 LightPath 2014© - http://www.jmrenouard.fr
  20. 20. $_GLOBALS: tableau des variables. $_SERVER: variables du serveur Web $_GET: variables d'un requête HTTP GET $_POST: variables d'un requête HTTP POST $_COOKIE: variables contenues dans les cookies 20 LightPath 2014© - http://www.jmrenouard.fr
  21. 21. $_FILES: variables contenant les informations sur les « fichiers Postés » $_ENV : variables d'environnement  $_REQUEST: variables d'entrée et peu sûres $_SESSION: variables contenues en session 21 LightPath 2014© - http://www.jmrenouard.fr
  22. 22. Global indique d'une variable fait partie de l'espace de nommage globale. Global est utilisé pour les variables dans les fonctions Static indique d'une variable n'est pas réinitialisé à la déclaration. 22 LightPath 2014© - http://www.jmrenouard.fr
  23. 23. Variable classique : ◦$a= 'bonjour'; Variables variables ◦$$a='monde'; => $bonjour='monde'; Utilisation ◦echo « $a ${$a} »; ◦echo « $a $bonjour »; 23 LightPath 2014© - http://www.jmrenouard.fr
  24. 24. Passage par les variables pré-définies : ◦$_GET ◦$_POST ◦$_COOKIE ◦$_FILES ◦$_ENV 24 LightPath 2014© - http://www.jmrenouard.fr
  25. 25. 25 LightPath 2014© - http://www.jmrenouard.fr
  26. 26. Sensible à la case Pas d'affectation possible define("FOO", "something"); echo FOO; 26 LightPath 2014© - http://www.jmrenouard.fr
  27. 27. Pas de réservation mémoire Pas affectation possible Idéal pour des paramètres invariants Performance  substitution 27 LightPath 2014© - http://www.jmrenouard.fr
  28. 28. 28 LightPath 2014© - http://www.jmrenouard.fr
  29. 29. Tout ce qui a une valeur Type d'expression ◦Fonctions ◦Affectations ◦Opérations ◦Appel de fonctions 29 LightPath 2014© - http://www.jmrenouard.fr
  30. 30. 30 LightPath 2014© - http://www.jmrenouard.fr
  31. 31. incrémentation/décrémentation: ++ -- Opérateurs arithmétiques : * / % + - ** Opérateurs de chaîne : + - . Opérateurs bit à bit : << >> & ^ | 31 LightPath 2014© - http://www.jmrenouard.fr
  32. 32. Opérateurs de comparaison : < <= > >= == != === Opérateurs logiques : && || and or not ! Opérateurs d'affectation : = += -= *= /= .= %= &= |= ^= <<= >>= 32 LightPath 2014© - http://www.jmrenouard.fr
  33. 33. 33 LightPath 2014© - http://www.jmrenouard.fr
  34. 34. If / else / elseif While / do-while For / foreach Break / continue switch 34 LightPath 2014© - http://www.jmrenouard.fr
  35. 35. Vrai si l'expression vaut différent de 0 ou TRUE Exemple : if ($a > $b) { echo "a est plus grand que b"; } elseif ($a == $b) { echo "a est égal à b"; } else { echo "a est plus petit que b"; } 35 LightPath 2014© - http://www.jmrenouard.fr
  36. 36. Expression du TANT QUE Expression des boucles Exemple : $i = 1; while ($i <= 10) { echo $i++; /* La valeur affiche est $i avant l'incrémentation */ } 36 LightPath 2014© - http://www.jmrenouard.fr
  37. 37. Raccourci d'expression while for (expr1; expr2; expr3) {...} Peut être traduit par : expr1; while (expr2) { ... expr3; } 37 LightPath 2014© - http://www.jmrenouard.fr
  38. 38. Instructions d'altération de boucle Break dans une boucle while, for, foreach ◦Fin d'itération. ◦Sortie de boucle Continue dans une bloucle : ◦Terminaison de la boucle courante ◦Passage à la boucle suivante 38 LightPath 2014© - http://www.jmrenouard.fr
  39. 39. Expression de choix Expression de l'alternative Expression du regroupement If / else / elseif : complexe > 3. Fonctionne aussi avec des chaînes 39 LightPath 2014© - http://www.jmrenouard.fr
  40. 40. 40 LightPath 2014© - http://www.jmrenouard.fr
  41. 41. Il s'agit d'une adresse Utilisé comme adresse lors de l'initialisation (=&) Utilisé comme variable simple le reste du temps Evite la recopie de zone mémoire Manipulation des adresses mémoire 41 LightPath 2014© - http://www.jmrenouard.fr
  42. 42. $a =1 $b =& $a; //b est une référence sur $a echo $a; //1 echo $b //1 $a=4 echo $b //4 $b = 30; echo $a //30 42 LightPath 2014© - http://www.jmrenouard.fr
  43. 43. 43 LightPath 2014© - http://www.jmrenouard.fr
  44. 44. Fonction : espace de nommage particulier Etanche depuis l'extérieur Regroupement de code commun Paramètre : ce qui rentre de l'extérieur Valeur de retour ce qui sort ou reste de la fonction 44 LightPath 2014© - http://www.jmrenouard.fr
  45. 45. Pas de paramètre Passage par copie Passage par référence Valeur par défaut Paramètres variables 45 LightPath 2014© - http://www.jmrenouard.fr
  46. 46. Pas de valeur possible La valeur peut-être de tout type Référence possible 46 LightPath 2014© - http://www.jmrenouard.fr
  47. 47. Les fonctions variables ◦$a= 'uneFonction'; ◦$a(); Les fonctions internes ◦Fonctions fournies par des modules PHP 47 LightPath 2014© - http://www.jmrenouard.fr
  48. 48. Les fonctions variables ◦$func='toto'; ◦function toto() { echo “cooll”;} ◦$func(); Possibilités de retour de reférence ◦function &retourne_ref() 48 LightPath 2014© - http://www.jmrenouard.fr
  49. 49. Argument par défaut ◦function ouvrir($passwd='toto') Références et paramètres ◦function lire(&$livre) 49 LightPath 2014© - http://www.jmrenouard.fr
  50. 50. Nouveautés PHP 5.6 Possibilité de gérer des arguments variables <?php function fvar($p1, ...$params) { printf(‘Parametre 1: %s’, $p1); $i=2; // $params est un tableau contenant le reste des arguments. foreach ($params as $pn ) { printf(‘Parametre %d: %d’,$i, $pn); $i++ } ?> LightPath 2014© - http://www.jmrenouard.fr 50
  51. 51. Exemple d’appel: fvar(1); fvar (1, 2); fvar (1, 2, 3); fvar (1, 2, 3, 4); fvar (1, 2, 3, 4, 5); LightPath 2014© - http://www.jmrenouard.fr 51
  52. 52. LightPath: ◦Société de conseil et d’ingénierie ◦Formations, Conseil, Audit et mise en oeuvre ◦jmrenouard@lightpath.fr Jean-Marie RENOUARD ◦jmrenouard@gmail.com ◦Twitter: @jmrenouard ◦http://www.jmrenouard.fr LightPath 2014© - http://www.jmrenouard.fr 52

×