mirror of
https://github.com/BreizhHardware/PHP.git
synced 2026-01-18 16:27:32 +01:00
Init
This commit is contained in:
8
TP1/.idea/.gitignore
generated
vendored
Normal file
8
TP1/.idea/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
8
TP1/.idea/TP1.iml
generated
Normal file
8
TP1/.idea/TP1.iml
generated
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="WEB_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
7
TP1/.idea/discord.xml
generated
Normal file
7
TP1/.idea/discord.xml
generated
Normal file
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="DiscordProjectSettings">
|
||||
<option name="show" value="PROJECT_FILES" />
|
||||
<option name="description" value="" />
|
||||
</component>
|
||||
</project>
|
||||
8
TP1/.idea/modules.xml
generated
Normal file
8
TP1/.idea/modules.xml
generated
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/TP1.iml" filepath="$PROJECT_DIR$/.idea/TP1.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
20
TP1/.idea/php.xml
generated
Normal file
20
TP1/.idea/php.xml
generated
Normal file
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="MessDetectorOptionsConfiguration">
|
||||
<option name="transferred" value="true" />
|
||||
</component>
|
||||
<component name="PHPCSFixerOptionsConfiguration">
|
||||
<option name="transferred" value="true" />
|
||||
</component>
|
||||
<component name="PHPCodeSnifferOptionsConfiguration">
|
||||
<option name="highlightLevel" value="WARNING" />
|
||||
<option name="transferred" value="true" />
|
||||
</component>
|
||||
<component name="PhpProjectSharedConfiguration" php_language_level="8.2" />
|
||||
<component name="PhpStanOptionsConfiguration">
|
||||
<option name="transferred" value="true" />
|
||||
</component>
|
||||
<component name="PsalmOptionsConfiguration">
|
||||
<option name="transferred" value="true" />
|
||||
</component>
|
||||
</project>
|
||||
32
TP1/TP1-PHP-Marquet.php
Normal file
32
TP1/TP1-PHP-Marquet.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
echo "<title>TP1 - PHP - Marquet</title>";
|
||||
echo "<h1>TP1 - PHP - Marquet</h1>";
|
||||
echo "<hr>";
|
||||
echo "<h2>Exercice 1</h2>";
|
||||
$citation = 'Citation de Coluche';
|
||||
$citation = strtoupper($citation);
|
||||
echo "<p><i>J'ai l'esprit large et je n'admets pas qu'on dise le contraire.</i> <b>$citation</b></p>";
|
||||
echo "<hr>";
|
||||
echo "<h2>Exercice 2</h2>";
|
||||
if(isset($citatio)){
|
||||
echo "La variable citatio existe";
|
||||
}
|
||||
else{
|
||||
echo "La variable citatio n'existe pas";
|
||||
}
|
||||
echo "<br>";
|
||||
if(isset($citation)){
|
||||
echo "La variable citation existe";
|
||||
}
|
||||
else{
|
||||
echo "La variable citation n'existe pas";
|
||||
}
|
||||
echo "<hr>";
|
||||
echo "<h2>Exercice 3</h2>";
|
||||
print_r($_SERVER);
|
||||
print_r($_GLOBALS);
|
||||
echo "<hr>";
|
||||
echo "<h2>Exercice 4</h2>";
|
||||
ini_set('display_errors', 1);
|
||||
echo ini_get('display_errors');
|
||||
?>
|
||||
186
TP2/TP2-PHP-Marquet.php
Normal file
186
TP2/TP2-PHP-Marquet.php
Normal file
@@ -0,0 +1,186 @@
|
||||
<?php
|
||||
echo "<title>TP2 - PHP - Marquet</title>";
|
||||
echo "<link rel='stylesheet' href='style.css'>";
|
||||
echo "<h1>TP2 - PHP - Marquet</h1>";
|
||||
echo "<hr>";
|
||||
echo "<h2>Exercice 1</h2>";
|
||||
$age = random_int(0, 100);
|
||||
echo "L'age de la personne est de : " . $age . " ans";
|
||||
echo "<br>";
|
||||
echo "Version if : ";
|
||||
if(($age) >= 70){
|
||||
echo "La personne est agé";
|
||||
}
|
||||
else if(($age) >= 50){
|
||||
echo "La personne est un sénior";
|
||||
}
|
||||
else if(($age) >= 20){
|
||||
echo "La personne est un adulte";
|
||||
}
|
||||
else{
|
||||
echo "La personne est un enfant";
|
||||
}
|
||||
echo "<br>";
|
||||
echo "Version switch : ";
|
||||
switch($age){
|
||||
case ($age >= 70):
|
||||
echo "La personne est agé";
|
||||
break;
|
||||
case ($age >= 50):
|
||||
echo "La personne est un sénior";
|
||||
break;
|
||||
case ($age >= 20):
|
||||
echo "La personne est un adulte";
|
||||
break;
|
||||
default:
|
||||
echo "La personne est un enfant";
|
||||
break;
|
||||
}
|
||||
echo "<hr>";
|
||||
echo "<h2>Exercice 2</h2>";
|
||||
$Fibo0 = 0;
|
||||
$Fibo1 = 1;
|
||||
$Fibo2 = 0;
|
||||
$i = 0;
|
||||
$tabFibo = array();
|
||||
echo "Suite de Fibonacci : ";
|
||||
while($i < 20){
|
||||
$Fibo2 = $Fibo0 + $Fibo1;
|
||||
$Fibo0 = $Fibo1;
|
||||
$Fibo1 = $Fibo2;
|
||||
$tabFibo[$i] = $Fibo2;
|
||||
$i++;
|
||||
}
|
||||
echo "<table border=1>";
|
||||
echo "<tr>";
|
||||
for($i = 0; $i < 20; $i++){
|
||||
echo "<td>F" . $i . "</td>";
|
||||
}
|
||||
echo "</tr>";
|
||||
echo "<tr>";
|
||||
for($i = 0; $i < 20; $i++){
|
||||
echo "<td>" . $tabFibo[$i] . "</td>";
|
||||
}
|
||||
echo "</tr>";
|
||||
echo "</table>";
|
||||
echo "Fn+1 / Fn";
|
||||
$Fibo0 = 0;
|
||||
$Fibo1 = 1;
|
||||
$Fibo2 = 0;
|
||||
$i = 0;
|
||||
$tabFibo2 = array();
|
||||
do{
|
||||
$Fibo2 = $Fibo0 + $Fibo1;
|
||||
$Fibo0 = $Fibo1;
|
||||
$Fibo1 = $Fibo2;
|
||||
$tabFibo2[$i] = $Fibo2 / $Fibo0;
|
||||
$i++;
|
||||
}while($i < 30);
|
||||
echo "<table border=1>";
|
||||
echo "<tr>";
|
||||
for($i = 0; $i < 30; $i++){
|
||||
echo "<td>F" . $i . "</td>";
|
||||
}
|
||||
echo "</tr>";
|
||||
echo "<tr>";
|
||||
for($i = 0; $i < 30; $i++){
|
||||
echo "<td>" . $tabFibo2[$i] . "</td>";
|
||||
}
|
||||
echo "</tr>";
|
||||
echo "</table>";
|
||||
echo "<hr>";
|
||||
echo "<h2>Exercice 3</h2>";
|
||||
$pi = 0;
|
||||
echo "Pi (15 iterations) = ";
|
||||
for($i = 1; $i <= 15; $i++){
|
||||
$pi += 1/($i**2);
|
||||
}
|
||||
$pi = sqrt($pi*6);
|
||||
echo $pi;
|
||||
echo "<br>";
|
||||
echo "Pi (150 iterations) = ";
|
||||
$pi = 0;
|
||||
for($i = 1; $i <= 150; $i++){
|
||||
$pi += 1/($i**2);
|
||||
}
|
||||
$pi = sqrt($pi*6);
|
||||
echo $pi;
|
||||
echo "<br>";
|
||||
echo "Pi (1500 iterations) = ";
|
||||
$pi = 0;
|
||||
for($i = 1; $i <= 1500; $i++){
|
||||
$pi += 1/($i**2);
|
||||
}
|
||||
$pi = sqrt($pi*6);
|
||||
echo $pi;
|
||||
echo "<br>";
|
||||
echo "Pi (15000 iterations) = ";
|
||||
$pi = 0;
|
||||
for($i = 1; $i <= 15000; $i++){
|
||||
$pi += 1/($i**2);
|
||||
}
|
||||
$pi = sqrt($pi*6);
|
||||
echo $pi;
|
||||
echo "<br>";
|
||||
echo "<hr>";
|
||||
echo "<h2>Exercice 4</h2>";
|
||||
echo "<h3>a/</h3>";
|
||||
$tabCita = array("Forest Gump" => "La vie c'est comme une boîte de chocolats, on ne sait jamais sur quoi on va tomber.",
|
||||
"Albert Einstein" => "L'informatique est la seule science où plus nous faisons de progrès, plus le problème reste le même.",
|
||||
"R. W. Hamming" => "Le véritable enjeu de l'informatique n'est pas de savoir comment traiter l'information, mais comment utiliser l'information pour comprendre le monde.",
|
||||
"Nicholas Negroponte" => "L'informatique est une discipline étrange. À chaque fois que vous résolvez un problème, un nouveau apparaît.",
|
||||
"Danny Hillis" => "L'informatique est le seul domaine d'ingénierie où les ingénieurs travaillent principalement avec des matériaux qu'ils ne comprennent pas vraiment : l'électricité et les idées.");
|
||||
foreach($tabCita as $key => $value){
|
||||
echo "$value <br>";
|
||||
}
|
||||
echo "<h3>b/</h3>";
|
||||
foreach($tabCita as $key => $value){
|
||||
echo "$key => $value <br>";
|
||||
}
|
||||
echo "<hr>";
|
||||
echo "<h2>Exercice 5</h2>";
|
||||
$nb = random_int(0, 10);
|
||||
echo "<table border=1'><thead><tr><th style='border: 1px solid #333;' colspan='2'>Table de $nb</th></tr></thead><tbody>";
|
||||
for ($i=1;$i<11;$i++){
|
||||
echo "<tr><td style='border: 1px solid #333;'>$i*$nb</td><td style='border: 1px solid #333;'>".($i*$nb)."</td></tr>";
|
||||
}
|
||||
echo "</tbody></table>";
|
||||
echo "<hr>";
|
||||
echo "<h2>Exercice 6</h2>";
|
||||
$nb = 2;
|
||||
$nbPremier = true;
|
||||
while($nb <= 97){
|
||||
$nbPremier = true;
|
||||
for($i = 2; $i < $nb; $i++){
|
||||
if($nb % $i == 0){
|
||||
$nbPremier = false;
|
||||
}
|
||||
}
|
||||
if($nbPremier){
|
||||
echo $nb . " ";
|
||||
}
|
||||
$nb++;
|
||||
}
|
||||
echo "<hr>";
|
||||
echo "<h2>Exercice 7</h2>";
|
||||
$taille = 5;
|
||||
$unite = "T";
|
||||
echo "Taille : " . $taille . $unite . " = ";
|
||||
switch($unite){
|
||||
case "K":
|
||||
$taille = $taille * 1024;
|
||||
break;
|
||||
case "M":
|
||||
$taille = $taille * 1024 * 1024;
|
||||
break;
|
||||
case "G":
|
||||
$taille = $taille * 1024 * 1024 * 1024;
|
||||
break;
|
||||
case "T":
|
||||
$taille = $taille * 1024 * 1024 * 1024 * 1024;
|
||||
break;
|
||||
}
|
||||
echo $taille;
|
||||
echo "octets";
|
||||
echo "<iframe src='../info.php' width='100%' height='100%'></iframe>";
|
||||
?>
|
||||
4
TP2/style.css
Normal file
4
TP2/style.css
Normal file
@@ -0,0 +1,4 @@
|
||||
body{
|
||||
background-color: #333333;
|
||||
color: white;
|
||||
}
|
||||
380
TP3/TP3-PHP-Marquet.php
Normal file
380
TP3/TP3-PHP-Marquet.php
Normal file
@@ -0,0 +1,380 @@
|
||||
<?php
|
||||
echo "<title>TP3 - PHP - Marquet</title>";
|
||||
echo "<link rel='stylesheet' href='style.css'>";
|
||||
echo "<h1>TP2 - PHP - Marquet</h1>";
|
||||
echo "<hr>";
|
||||
echo "<h2>Exercice 1</h2>";
|
||||
function increment(){
|
||||
static $i = 0;
|
||||
$i++;
|
||||
echo $i;
|
||||
}
|
||||
increment();
|
||||
echo "<br>";
|
||||
increment();
|
||||
echo "<br>";
|
||||
increment();
|
||||
echo "<hr>";
|
||||
echo "<h2>Exercice 2</h2>";
|
||||
function modifVar(&$var){
|
||||
$var = 10;
|
||||
}
|
||||
$var = 5;
|
||||
echo "Avant : " . $var;
|
||||
echo "<br>";
|
||||
modifVar($var);
|
||||
echo "Après : " . $var;
|
||||
echo "<hr>";
|
||||
echo "<h2>Exercice 3</h2>";
|
||||
$identite = ['alain', 'basile', 'David', 'Edgar'];
|
||||
$age = [1, 15, 35, 65];
|
||||
$mail = ['penom_nom@gtail.be', 'truc@bruce.zo', 'caro@caramel.org', 'trop@monmel.fr'];
|
||||
function domaineExtension($mail){
|
||||
$domaine = substr($mail, strpos($mail, '@') + 1, strpos($mail, '.') - strpos($mail, '@') - 1);
|
||||
$extension = substr($mail, strpos($mail, '.') + 1);
|
||||
return array($domaine, $extension);
|
||||
}
|
||||
echo "Domaine et extension du mail penom_nom@gtail.be : " . domaineExtension($mail[0])[0] . " et " . domaineExtension($mail[0])[1];
|
||||
echo "<br>";
|
||||
echo "Domaine et extension du mail truc@bruce.zo : " . domaineExtension($mail[1])[0] . " et " . domaineExtension($mail[1])[1];
|
||||
echo "<br>";
|
||||
function affiche($identite, $age, $mail){
|
||||
$i = random_int(0, 3);
|
||||
echo "Bonjour " . ucfirst($identite[$i]) . ", vous avez " . $age[$i] . " ans et votre mail est " . $mail[$i];
|
||||
}
|
||||
affiche($identite, $age, $mail);
|
||||
echo "<hr>";
|
||||
echo "<h2>Exercice 4</h2>";
|
||||
function ligne(){
|
||||
for($i = 0; $i < 5; $i++){
|
||||
echo "*";
|
||||
}
|
||||
echo "<br>";
|
||||
}
|
||||
echo "ligne :";
|
||||
echo "<br>";
|
||||
ligne();
|
||||
echo "<br>";
|
||||
function carre_plein(){
|
||||
for($i = 0; $i < 5; $i++){
|
||||
ligne();
|
||||
}
|
||||
}
|
||||
echo "carre_plein :";
|
||||
echo "<br>";
|
||||
carre_plein();
|
||||
echo "<br>";
|
||||
function triangle_iso(){
|
||||
for($i = 1; $i < 6; $i++){
|
||||
for($j = 0; $j < $i; $j++){
|
||||
echo "*";
|
||||
}
|
||||
echo "<br>";
|
||||
}
|
||||
}
|
||||
echo "triangle_iso :";
|
||||
echo "<br>";
|
||||
triangle_iso();
|
||||
echo "<br>";
|
||||
function carre_vide(){
|
||||
for($i = 0; $i < 5; $i++){
|
||||
if($i == 0 || $i == 4){
|
||||
ligne();
|
||||
}
|
||||
else{
|
||||
echo "*";
|
||||
for($j = 0; $j < 3; $j++){
|
||||
echo " ";
|
||||
}
|
||||
echo "*";
|
||||
echo "<br>";
|
||||
}
|
||||
}
|
||||
}
|
||||
echo "carre_vide :";
|
||||
echo "<br>";
|
||||
carre_vide();
|
||||
echo "<br>";
|
||||
function triangle_vide(){
|
||||
for($i = 1; $i < 6; $i++){
|
||||
if($i == 1){
|
||||
echo "*";
|
||||
echo "<br>";
|
||||
}
|
||||
else if($i == 5){
|
||||
for($j = 0; $j < 5; $j++){
|
||||
echo "*";
|
||||
}
|
||||
echo "<br>";
|
||||
}
|
||||
else{
|
||||
echo "*";
|
||||
for($j = 0; $j < $i - 2; $j++){
|
||||
echo " ";
|
||||
}
|
||||
echo "*";
|
||||
echo "<br>";
|
||||
}
|
||||
}
|
||||
}
|
||||
echo "triangle_vide :";
|
||||
echo "<br>";
|
||||
triangle_vide();
|
||||
echo "<br>";
|
||||
function triangle_vide_inv(){
|
||||
for($i = 1; $i < 6; $i++){
|
||||
if($i == 1){
|
||||
for($j = 0; $j < 5; $j++){
|
||||
echo "*";
|
||||
}
|
||||
echo "<br>";
|
||||
}
|
||||
else if($i == 5){
|
||||
echo "*";
|
||||
echo "<br>";
|
||||
}
|
||||
else{
|
||||
echo "*";
|
||||
for($j = 0; $j < 5 - $i; $j++){
|
||||
echo " ";
|
||||
}
|
||||
echo "*";
|
||||
echo "<br>";
|
||||
}
|
||||
}
|
||||
}
|
||||
echo "triangle_vide_inv :";
|
||||
echo "<br>";
|
||||
triangle_vide_inv();
|
||||
echo "<br>";
|
||||
echo "<hr>";
|
||||
echo "<h2>Exercice 5</h2>";
|
||||
function chiffrement($message, $decalage){
|
||||
$message = strtoupper($message);
|
||||
$message = str_split($message);
|
||||
$messageChiffre = "";
|
||||
foreach($message as $lettre){
|
||||
if($lettre == " "){
|
||||
$messageChiffre .= " ";
|
||||
}
|
||||
else{
|
||||
$messageChiffre .= chr(ord($lettre) + $decalage);
|
||||
}
|
||||
}
|
||||
return $messageChiffre;
|
||||
}
|
||||
echo "Chiffrement de 'Je t'aime Cléo' avec un décalage de 3 : " . chiffrement("Je t'aime Cléo", 3);
|
||||
echo "<br>";
|
||||
function dechiphrement($message, $decalage){
|
||||
$message = strtoupper($message);
|
||||
$message = str_split($message);
|
||||
$messageDechiffre = "";
|
||||
foreach($message as $lettre){
|
||||
if($lettre == " "){
|
||||
$messageDechiffre .= " ";
|
||||
}
|
||||
else{
|
||||
$messageDechiffre .= chr(ord($lettre) - $decalage);
|
||||
}
|
||||
}
|
||||
return $messageDechiffre;
|
||||
}
|
||||
echo "Déchiffrement de 'MH W*DLPH FOƬR' avec un décalage de 3 : " . dechiphrement("MH W*DLPH FOƬR", 3);
|
||||
echo "<br>";
|
||||
echo "<hr>";
|
||||
echo "<h2>Exercice 6</h2>";
|
||||
function chiffrementViginere($message, $cle){
|
||||
$message = strtoupper($message);
|
||||
$message = str_split($message);
|
||||
$cle = strtoupper($cle);
|
||||
$cle = str_split($cle);
|
||||
$messageChiffre = "";
|
||||
$j = 0;
|
||||
foreach($message as $lettre){
|
||||
if($lettre == " "){
|
||||
$messageChiffre .= " ";
|
||||
}
|
||||
else{
|
||||
$messageChiffre .= chr(ord($lettre) + ord($cle[$j]) - 65);
|
||||
$j++;
|
||||
if($j == count($cle)){
|
||||
$j = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $messageChiffre;
|
||||
}
|
||||
function dechiffrementViginere($message, $cle){
|
||||
$message = strtoupper($message);
|
||||
$message = str_split($message);
|
||||
$cle = strtoupper($cle);
|
||||
$cle = str_split($cle);
|
||||
$messageDechiffre = "";
|
||||
$j = 0;
|
||||
foreach($message as $lettre){
|
||||
if($lettre == " "){
|
||||
$messageDechiffre .= " ";
|
||||
}
|
||||
else{
|
||||
$messageDechiffre .= chr(ord($lettre) - ord($cle[$j]) + 65);
|
||||
$j++;
|
||||
if($j == count($cle)){
|
||||
$j = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $messageDechiffre;
|
||||
}
|
||||
echo "Chiffrement de 'Je t'aime Cléo' avec la clé 'Cleo' : " . chiffrementViginere("Je t'aime Cléo", "Cleo");
|
||||
echo "<br>";
|
||||
echo "Déchiffrement de 'LP X5CTQS EWǷQ' avec la clé 'Cleo' : " . dechiffrementViginere("LP X5CTQS EWǷQ", "Cleo");
|
||||
echo "<br>";
|
||||
echo "<hr>";
|
||||
echo "<h2>Exercice 7</h2>";
|
||||
$annuaire=array(
|
||||
"PUJOL Olivier"=>"03 89 72 84 48",
|
||||
"IMBERT Jo"=>"03 89 36 06 05",
|
||||
"SPIEGEL Pierre"=>"03 87 67 92 37",
|
||||
"THOUVENOT Frédéric"=>"01 42 86 02 12",
|
||||
"MEGEL Pierre"=>"09 59 71 46 96",
|
||||
"SUCHET Loïc"=>"03 89 33 10 54",
|
||||
"GIROIS Francis"=>"03 88 01 21 15",
|
||||
"HOFFMANN Emmanuel"=>"03 89 69 20 05",
|
||||
"KELLER Fabien"=>"04 18 52 34 25",
|
||||
"LEY Jean-Marie"=>"03 89 43 17 85",
|
||||
"ZOELLE Thomas"=>"04 18 65 67 69",
|
||||
"WILHELM Olivier"=>"03 89 60 48 78",
|
||||
"BLIN Nathalie"=>"01 28 59 23 25",
|
||||
"BICARD Pierre-Eric"=>"03 89 69 25 82",
|
||||
"ZIEGLER Thierry"=>"03 89 06 33 89",
|
||||
"BADER Jean"=>"03 89 25 65 72",
|
||||
"ROSSO Anne-Sophie"=>"01 56 20 02 36",
|
||||
"ROTTNER Thierry"=>"03 88 29 61 54",
|
||||
"WEBER Joao"=>"03 89 35 45 20",
|
||||
"SCHILLINGER Olivier"=>"03 84 21 38 40",
|
||||
"BICARD Muriel"=>"03 89 33 47 99 ",
|
||||
"KELLER Christian"=>"03 88 19 16 10 ",
|
||||
"GROELLY Antonio"=>"03 89 33 60 63",
|
||||
"ALLARD Aline"=>"03 89 56 49 19",
|
||||
"WINNINGER Bénédicte"=>"04 16 14 86 66");
|
||||
function afficheAnnuaire($annuaire){
|
||||
ksort($annuaire);
|
||||
echo "<table>";
|
||||
echo "<tr>";
|
||||
echo "<th>Nom</th>";
|
||||
echo "<th>Numéro</th>";
|
||||
echo "</tr>";
|
||||
foreach($annuaire as $key => $value){
|
||||
echo "<tr>";
|
||||
echo "<td>" . $key . "</td>";
|
||||
echo "<td>" . $value . "</td>";
|
||||
echo "</tr>";
|
||||
}
|
||||
echo "</table>";
|
||||
}
|
||||
afficheAnnuaire($annuaire);
|
||||
echo "<hr>";
|
||||
echo "<h2>Exercice 8</h2>";
|
||||
function lampe($interrupteur1, $interrupteur2, $interrupteur3){
|
||||
if($interrupteur1 == true && $interrupteur2 == true && $interrupteur3 == true){
|
||||
echo "La lampe est allumée";
|
||||
}
|
||||
else if($interrupteur1 == true && $interrupteur2 == true && $interrupteur3 == false){
|
||||
echo "La lampe est éteinte";
|
||||
}
|
||||
else if($interrupteur1 == true && $interrupteur2 == false && $interrupteur3 == true){
|
||||
echo "La lampe est éteinte";
|
||||
}
|
||||
else if($interrupteur1 == true && $interrupteur2 == false && $interrupteur3 == false){
|
||||
echo "La lampe est allumée";
|
||||
}
|
||||
else if($interrupteur1 == false && $interrupteur2 == true && $interrupteur3 == true){
|
||||
echo "La lampe est éteinte";
|
||||
}
|
||||
else if($interrupteur1 == false && $interrupteur2 == true && $interrupteur3 == false){
|
||||
echo "La lampe est allumée";
|
||||
}
|
||||
else if($interrupteur1 == false && $interrupteur2 == false && $interrupteur3 == true){
|
||||
echo "La lampe est allumée";
|
||||
}
|
||||
else if($interrupteur1 == false && $interrupteur2 == false && $interrupteur3 == false){
|
||||
echo "La lampe est éteinte";
|
||||
}
|
||||
}
|
||||
echo "Lampe avec les interrupteurs 1, 2 et 3 allumés : ";
|
||||
lampe(true, true, true);
|
||||
echo "<br>";
|
||||
echo "<hr>";
|
||||
echo "<h2>Exercice 9</h2>";
|
||||
$clients = ["1"=>"Dulong","ville 1"=>"Paris","age 1"=>"35",
|
||||
"2"=>"Leparc","ville 2"=>"Lyon","age 2"=>"47",
|
||||
"3"=>"Dubos","ville 3"=>"Tours","age 3"=>"58"];
|
||||
$clients["4"] = "Duval";
|
||||
$clients["ville 4"] = "Nantes";
|
||||
$clients["age 4"] = "24";
|
||||
function afficheClient($client){
|
||||
echo "<table>";
|
||||
echo "<tr>";
|
||||
echo "<th>Numéro</th>";
|
||||
echo "<th>Nom</th>";
|
||||
echo "<th>Ville</th>";
|
||||
echo "<th>Age</th>";
|
||||
echo "</tr>";
|
||||
for($i = 1; $i <= count($client) / 3; $i++){
|
||||
echo "<tr>";
|
||||
echo "<td>" . $i . "</td>";
|
||||
echo "<td>" . $client[$i] . "</td>";
|
||||
echo "<td>" . $client["ville " . $i] . "</td>";
|
||||
echo "<td>" . $client["age " . $i] . "</td>";
|
||||
echo "</tr>";
|
||||
}
|
||||
echo "</table>";
|
||||
}
|
||||
afficheClient($clients);
|
||||
echo "<hr>";
|
||||
echo "<h2>Exercice 10</h2>";
|
||||
function estPalindrome($mot){
|
||||
$mot = strtoupper($mot);
|
||||
$mot = str_split($mot);
|
||||
$motInverse = array_reverse($mot);
|
||||
$motInverse = implode("", $motInverse);
|
||||
if(implode("", $mot) == $motInverse){
|
||||
echo "Oui";
|
||||
}
|
||||
else{
|
||||
echo "Non";
|
||||
}
|
||||
}
|
||||
echo "Est-ce que 'radar' est un palindrome ? ";
|
||||
estPalindrome("radar");
|
||||
echo "<br>";
|
||||
echo "Est-ce que 'radars' est un palindrome ? ";
|
||||
estPalindrome("radars");
|
||||
echo "<hr>";
|
||||
echo "<h2>Exercice 11</h2>";
|
||||
//Ecrire une fonction qui vérifie si un numéro de carte bancaire est valide ou pas. Pour cela, il est demandé de se baser sur la formule de Luhn (https://fr.wikipedia.org/wiki/Formule_de_Luhn)
|
||||
function estValide($numero){
|
||||
$numero = str_split($numero);
|
||||
$somme = 0;
|
||||
for($i = 0; $i < count($numero); $i++){
|
||||
if($i % 2 == 0){
|
||||
$numero[$i] *= 2;
|
||||
if($numero[$i] > 9){
|
||||
$numero[$i] -= 9;
|
||||
}
|
||||
}
|
||||
$somme += $numero[$i];
|
||||
}
|
||||
if($somme % 10 == 0){
|
||||
echo "Oui";
|
||||
}
|
||||
else{
|
||||
echo "Non";
|
||||
}
|
||||
}
|
||||
echo "Est-ce que '4970100000000000' est un numéro de carte bancaire valide ? ";
|
||||
estValide("4970100000000000");
|
||||
echo "<br>";
|
||||
echo "Est-ce que '5130240038105643' est un numéro de carte bancaire valide ? ";
|
||||
estValide("5130240038105643");
|
||||
?>
|
||||
4
TP3/style.css
Normal file
4
TP3/style.css
Normal file
@@ -0,0 +1,4 @@
|
||||
body{
|
||||
background-color: #333333;
|
||||
color: white;
|
||||
}
|
||||
69
TP4/TP4-PHP-Marquet.php
Normal file
69
TP4/TP4-PHP-Marquet.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
echo "<title>TP4 - PHP - Marquet</title>";
|
||||
echo "<link rel='stylesheet' href='style.css'>";
|
||||
echo "<h1>TP4 - PHP - Marquet</h1>";
|
||||
setlocale(LC_TIME, 'fr_FR.utf8', 'fr_FR', 'fr', 'fra', 'french');
|
||||
echo "<hr>";
|
||||
echo "<h2>Exercice 1</h2>";
|
||||
$date = new DateTime();
|
||||
echo "<strong>EN :</strong> " . $date->format('l d F Y') . "<br>";
|
||||
echo "<strong>FR :</strong> " . strftime('%A %d %B %Y') . "<br>";
|
||||
echo "<strong>Date et heure :</strong> " . $date->format('d/m/Y H:i') . "<br>";
|
||||
echo "Il est passé " . $date->getTimestamp() . " secondes depuis l'apparition d'UNIX";
|
||||
echo "<hr>";
|
||||
echo "<h2>Exercice 2</h2>";
|
||||
$dateNaissance = new DateTime('2004-03-12');
|
||||
$dateActuelle = new DateTime();
|
||||
$interval = $dateNaissance->diff($dateActuelle);
|
||||
echo "Date de naissance : " . $dateNaissance->format('d/m/Y') . "<br>";
|
||||
echo "Date actuelle : " . $dateActuelle->format('d/m/Y') . "<br>";
|
||||
echo "Age : " . $interval->format('%y ans, %m mois et %d jours');
|
||||
echo "<hr>";
|
||||
echo "<h2>Exercice 3</h2>";
|
||||
$dateLune = new DateTime('2023-09-29 11:59:00');
|
||||
$dateActuelle = new DateTime();
|
||||
$dateProchaineLune = $dateLune->add(new DateInterval('P29DT12H44M3S'));
|
||||
$interval = $dateActuelle->diff($dateProchaineLune);
|
||||
echo "Date de la prochaine pleine lune : " . $dateProchaineLune->format('d/m/Y H:i:s') . "<br>";
|
||||
$dateCentiemeLune = $dateLune->add(new DateInterval('P2900DT1200H4400M300S'));
|
||||
echo "Date de la 100ème prochaine pleine lune : " . $dateCentiemeLune->format('d/m/Y H:i:s') . "<br>";
|
||||
echo "Il reste " . $interval->format('%d jours, %h heures, %i minutes et %s secondes') . " avant la prochaine pleine lune";
|
||||
echo "<hr>";
|
||||
echo "<h2>Exercice 4</h2>";
|
||||
if(checkdate(2, 29, 1962)){
|
||||
echo "La date du 29 février 1962 a existé";
|
||||
}
|
||||
else{
|
||||
echo "La date du 29 février 1962 n'a pas existé";
|
||||
}
|
||||
echo "<hr>";
|
||||
echo "<h2>Exercice 5</h2>";
|
||||
$date = mktime(0, 0, 0, 3, 3, 1993);
|
||||
echo "Le 3 mars 1993 était un " . strftime('%A', $date);
|
||||
echo "<hr>";
|
||||
echo "<h2>Exercice 6</h2>";
|
||||
echo "Les années bissextiles entre 2020 et 2062 sont : <br>";
|
||||
for($i = 2020; $i <= 2062; $i++){
|
||||
$date = mktime(0, 0, 0, 2, 29, $i);
|
||||
if(checkdate(2, 29, $i)){
|
||||
echo $i . "<br>";
|
||||
}
|
||||
}
|
||||
echo "<hr>";
|
||||
echo "<h2>Exercice 7</h2>";
|
||||
echo "Les 1er mai entre 2022 et 2031 sont : <br>";
|
||||
for($i = 2022; $i <= 2031; $i++){
|
||||
$date = mktime(0, 0, 0, 5, 1, $i);
|
||||
if(strftime('%A', $date) == "samedi" || strftime('%A', $date) == "dimanche"){
|
||||
echo "Le 1er mai " . $i . " est un " . strftime('%A', $date) . " donc weekend non prolongé <br>";
|
||||
}
|
||||
else{
|
||||
if(strftime('%A', $date) == "vendredi" || strftime('%A', $date) == "lundi"){
|
||||
echo "Le 1er mai " . $i . " est un " . strftime('%A', $date) . " donc weekend prolongé <br>";
|
||||
}
|
||||
else{
|
||||
echo "Le 1er mai " . $i . " est un " . strftime('%A', $date) . " donc weekend non prolongé <br>";
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
4
TP4/style.css
Normal file
4
TP4/style.css
Normal file
@@ -0,0 +1,4 @@
|
||||
body{
|
||||
background-color: #333333;
|
||||
color: white;
|
||||
}
|
||||
56
TP5/TP5-PHP-Marquet.php
Normal file
56
TP5/TP5-PHP-Marquet.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>TP5 - PHP - Marquet</title>
|
||||
<link rel="stylesheet" href="style.css">
|
||||
</head>
|
||||
<body>
|
||||
<h1>TP5 - PHP - Marquet</h1>
|
||||
<hr>
|
||||
<h2>Exercice 1</h2>
|
||||
<form action="TP5-PHP-Marquet.php" method="post">
|
||||
<label for="fahrenheit">Température en Fahrenheit : </label>
|
||||
<input type="number" name="fahrenheit" id="fahrenheit">
|
||||
<input type="submit" value="Convertir">
|
||||
</form>
|
||||
<?php
|
||||
if(isset($_POST['fahrenheit'])){
|
||||
$fahrenheit = $_POST['fahrenheit'];
|
||||
$celsius = ($fahrenheit - 32) * 5 / 9;
|
||||
echo $fahrenheit . "°F = " . $celsius . "°C";
|
||||
}
|
||||
?>
|
||||
<form action="TP5-PHP-Marquet.php" method="get">
|
||||
<label for="fahrenheit">Température en Fahrenheit : </label>
|
||||
<input type="number" name="fahrenheit" id="fahrenheit">
|
||||
<input type="submit" value="Convertir">
|
||||
</form>
|
||||
<?php
|
||||
if(isset($_GET['fahrenheit'])){
|
||||
$fahrenheit = $_GET['fahrenheit'];
|
||||
$celsius = ($fahrenheit - 32) * 5 / 9;
|
||||
echo $fahrenheit . "°F = " . $celsius . "°C";
|
||||
}
|
||||
?>
|
||||
<hr>
|
||||
<h2>Exercice 2</h2>
|
||||
<form action="TP5-PHP-Marquet.php" method="post">
|
||||
<label for="Nom">Nom : </label>
|
||||
<input type="text" name="Nom" id="Nom">
|
||||
<label for="Prenom">Prénom : </label>
|
||||
<input type="text" name="Prenom" id="Prenom">
|
||||
<label for="Niveau">Niveau : </label>
|
||||
<input type="radio" name="Débutant" id="Débutant">
|
||||
<input type="radio" name="Avancé" id="Avancé">
|
||||
<input type="button" value="Envoyer">
|
||||
</form>
|
||||
<?php
|
||||
if(isset($_POST['Nom']) && isset($_POST['Prenom']) && isset($_POST['Niveau'])){
|
||||
$nom = $_POST['Nom'];
|
||||
$prenom = $_POST['Prenom'];
|
||||
$niveau = $_POST['Niveau'];
|
||||
echo "Nom : " . $nom . "<br>Prénom : " . $prenom . "<br>Niveau : " . $niveau;
|
||||
}
|
||||
?>
|
||||
</html>
|
||||
4
TP5/style.css
Normal file
4
TP5/style.css
Normal file
@@ -0,0 +1,4 @@
|
||||
body{
|
||||
background-color: #333333;
|
||||
color: white;
|
||||
}
|
||||
Reference in New Issue
Block a user