diff --git a/2020-2021/TD2/TP2-eno.pdf b/2020-2021/TD2/TP2-eno.pdf new file mode 100644 index 0000000..50c51a1 Binary files /dev/null and b/2020-2021/TD2/TP2-eno.pdf differ diff --git a/2020-2021/TD2/index.php b/2020-2021/TD2/index.php index 2995f3e..3e4e314 100755 --- a/2020-2021/TD2/index.php +++ b/2020-2021/TD2/index.php @@ -4,9 +4,87 @@ * @Author: JunkJumper * @Link: https://github.com/JunkJumper * @Copyright: Creative Common 4.0 (CC BY 4.0) - * @Create Time: 07-09-2020 10:44:25 - * @Description: M314 - TD1 + * @Create Time: 12-09-2020 11:32:41 + * @Description: M314 - TD2 */ + +$aj = "Applejack is best pony !"; +$cmc = "Applebloom is Applejack's little sister, Scootaloo is Rainbow Dash's little filly; Sweatie Belle is Rarity's little sister."; +$song = "We've traveled the road of generations… Joined by a common bond; We sing our song 'cross the pony nation; From Equestria and beyond… We're Apples forever, Apples together ! We're family, but so much more ! No matter what comes, we will face the weather ! We're Apples to the core…"; + +$namesO = array ( + "mots", + "phrases", + "points", + "virgules", + "point virgules", + "points d'exclamation", + "points d'interrogation", + "points de suspension" +); + +function nbWord(String $s) : int { + return sizeof(explode(" ", $s)); +} + +function nbSentence(String $s) : String { + $point = explode(".", $s); + $exc = explode("!", $s); + $interr = explode("?", $s); + $suspen = explode("…", $s); + return sizeof($point)-1 + sizeof($exc)-1 + sizeof($interr)-1 + sizeof($suspen)-1; +} + +function reverseSentence(String $s) : void { + $sTab=explode(" ", $s); + $retour=""; + for ($i=(sizeof($sTab)-1); $i >= 0; $i--) { + echo $sTab[$i] ." "; + } +} + +function keepOccurences(String $s) : array { + $tabCount = array( + 0, //"mots" + 0, //"phrases" + 0, //"points" + 0, //"virgules" + 0, //"point virgules" + 0, //"exclamation" + 0, //"interrogation" + 0 //"suspension + ); + for ($i=0; $i < strlen($s) ; $i++) { + switch ($s[$i]) { + case ".": + $tabCount[2]++; + break; + case ",": + $tabCount[3]++; + break; + case ";": + $tabCount[4]++; + break; + case "!": + $tabCount[5]++; + break; + case "?": + $tabCount[6]++; + break; + case "…": + $tabCount[7]++; + break; + default: + # code... + break; + } + } + + $tabCount[0] = nbWord($s); + $tabCount[1] = nbSentence($s); + return $tabCount; +} + ?> @@ -14,15 +92,63 @@ M314 - TD1 +

M314 - TD2 : Manipulation des boucles, expressions conditionnelles et introduction aux tables globales

+

Les deux phrases qui seront utilisées dans ce TD sont et . + +

Manipulations des chaînes de caractères et tables

+ + +

1) Dans "" il y a mots.
+ Dans "" il y a mots.

+ +

2) Dans "" il y a phrase.
+ Dans "" il y a phrases.

+ +

3) "" inversé donne "".
+ "" inversé donne "".
+ +

4) Dans "", il y a + .
+ + Dans "", il y a + .
+ + Dans "", il y a + + +

+