"1.4 fini TD2"
This commit is contained in:
parent
a001aab11f
commit
6441a8841c
BIN
2020-2021/TD2/TP2-eno.pdf
Normal file
BIN
2020-2021/TD2/TP2-eno.pdf
Normal file
Binary file not shown.
@ -4,9 +4,87 @@
|
|||||||
* @Author: JunkJumper
|
* @Author: JunkJumper
|
||||||
* @Link: https://github.com/JunkJumper
|
* @Link: https://github.com/JunkJumper
|
||||||
* @Copyright: Creative Common 4.0 (CC BY 4.0)
|
* @Copyright: Creative Common 4.0 (CC BY 4.0)
|
||||||
* @Create Time: 07-09-2020 10:44:25
|
* @Create Time: 12-09-2020 11:32:41
|
||||||
* @Description: M314 - TD1
|
* @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;
|
||||||
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<html>
|
<html>
|
||||||
@ -14,15 +92,63 @@
|
|||||||
<head>
|
<head>
|
||||||
<title>M314 - TD1</title>
|
<title>M314 - TD1</title>
|
||||||
<link rel="icon" type="image/png" href="https://www.junkjumper-projects.com/umming_lines_paint.png" />
|
<link rel="icon" type="image/png" href="https://www.junkjumper-projects.com/umming_lines_paint.png" />
|
||||||
|
<h1>M314 - TD2 : Manipulation des boucles, expressions conditionnelles et introduction aux tables globales</h1>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
<p>Les deux phrases qui seront utilisées dans ce TD sont <?php echo $aj ?> et <?php echo $cmc ?> .
|
||||||
|
|
||||||
|
<h2>Manipulations des chaînes de caractères et tables</h1>
|
||||||
|
|
||||||
|
|
||||||
|
<p>1) Dans <b>"</b><?php echo $aj ?><b>"</b> il y a <?php echo nbWord($aj)?> mots.<br />
|
||||||
|
Dans <b>"</b><?php echo $cmc ?><b>"</b> il y a <?php echo nbWord($cmc)?> mots.</p>
|
||||||
|
|
||||||
|
<p>2) Dans <b>"</b><?php echo $aj ?><b>"</b> il y a <?php echo nbSentence($aj)?> phrase.<br />
|
||||||
|
Dans <b>"</b><?php echo $cmc ?><b>"</b> il y a <?php echo nbSentence($cmc)?> phrases.</p>
|
||||||
|
|
||||||
|
<p>3) <b>"</b><?php echo $aj ?><b>"</b> inversé donne <b>"</b><?php echo reverseSentence($aj)?><b>"</b>.<br />
|
||||||
|
<b>"</b><?php echo $cmc ?><b>"</b> inversé donne <b>"</b><?php echo reverseSentence($cmc)?><b>"</b>.<br />
|
||||||
|
|
||||||
|
<p>4) Dans <b>"</b><?php echo $aj ?><b>"</b>, il y a
|
||||||
|
<?php
|
||||||
|
$tab = keepOccurences($aj);
|
||||||
|
|
||||||
|
for ($i=0; $i < 8 ; $i++) {
|
||||||
|
echo $tab[$i] . " " . $namesO[$i] . ", ";
|
||||||
|
}
|
||||||
|
?>.<br />
|
||||||
|
|
||||||
|
Dans <b>"</b><?php echo $cmc ?><b>"</b>, il y a
|
||||||
|
<?php
|
||||||
|
$tab = keepOccurences($cmc);
|
||||||
|
|
||||||
|
for ($i=0; $i < 8 ; $i++) {
|
||||||
|
echo $tab[$i] . " " . $namesO[$i] . ", ";
|
||||||
|
}
|
||||||
|
?>. <br/>
|
||||||
|
|
||||||
|
Dans <b>"</b><?php echo $song ?><b>"</b>, il y a
|
||||||
|
<?php
|
||||||
|
$tab = keepOccurences($song);
|
||||||
|
|
||||||
|
for ($i=0; $i < 8 ; $i++) {
|
||||||
|
echo $tab[$i] . " " . $namesO[$i] . ", ";
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
|
</p>
|
||||||
|
|
||||||
<a href="..">
|
<a href="..">
|
||||||
<button class="button blue">Retour à la page précédente</button>
|
<button class="button blue">Retour à la page précédente</button>
|
||||||
</a>
|
</a>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
h1, h2, h3, h4, h5, h6 {
|
||||||
|
color: #4c6e8a;
|
||||||
|
}
|
||||||
|
|
||||||
.button {
|
.button {
|
||||||
border: none;
|
border: none;
|
||||||
color: white;
|
color: white;
|
||||||
@ -39,6 +165,10 @@
|
|||||||
background-color: #4c6e8a;
|
background-color: #4c6e8a;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
b {
|
||||||
|
color: red;
|
||||||
|
}
|
||||||
|
|
||||||
/* Green */
|
/* Green */
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user