1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="fr" xml:lang="fr">
<head>
<title>Dictionnaire de Cuisine et synonymes</title>
<link rel="stylesheet" type="text/css" media="all" href="style.css" />
</head>
<body>
<h1>Dictionnaire de Cuisine et synonymes</h1>
<?
set_magic_quotes_runtime(0);
$fichier = 'dico_cuisine.txt';
switch ($_POST['action'])
{
case "ecrire":
function formate_machaine($chaine)
{
$chaine = str_replace('\n', '', $chaine);
$chaine = str_replace('|', '', $chaine);
$chaine = strip_tags($chaine);
$chaine = trim($chaine);
$chaine = substr($chaine, 0, 100);
return $chaine;
}
$mot = formate_machaine($_POST['mot']);
$synonyme = formate_machaine($_POST['synonyme']);
if($mot != '' and $synonyme != '')
{
if(filesize($fichier)>3000) $mode = 'w'; else $mode = 'a';
$fp = fopen($fichier, $mode);
fputs($fp, "$mot|$synonyme");
fputs($fp, "\n");
fclose($fp);
echo '<p>Mot et synonyme ajoutés !</p>';
echo '<p><a href="'.$_SERVER['PHP_SELF'].'">Retour</a></p>';
}
else
{
echo '<p>Erreur, veuillez remplir les deux champs !</p>';
echo '<p><a href="'.$_SERVER['PHP_SELF'].'">Retour</a></p>';
} break;
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" name="ecriture">
<input type="hidden" name="action" value="ecrire" />
<table summary="Ecriture dans le fichier" border="1">
<tr class="titre">
<td colspan="2">Ecriture dans le fichier</td>
</tr>
<tr>
<td>Mot</td>
<td>
<input type="text" name="mot" size="30" maxlength="30" />
</td> </tr>
<tr> <td>Synonyme</td>
<td>
<input type="text" name="synonyme" size="30" maxlength="100" />
</td> </tr>
<tr> <td> </td>
<td>
<input type="submit" name="envoyer" value="Et Hop!" />
</td></tr></table>
</form>
<table summary="Lecture du fichier">
<tr class="titre">
<td colspan="2">Lecture du fichier</td>
</tr>
<?
if(file_exists($fichier))
{
$fp = fopen($fichier, 'r');
while (!feof($fp))
{
$ligne = fgets($fp, 4096);
$liste = explode('|', $ligne);
$mot = htmlentities($liste[0]);
$synonyme = htmlentities($liste[1]);
if(get_magic_quotes_gpc())
{
$mot = stripslashes($mot);
$synonyme = stripslashes($synonyme);
}
if($mot != '' and $synonyme != '')
{
echo '<tr>';
echo '<td>' . $mot . '</td>';
echo '<td>' . $synonyme . '</td>';
echo '</tr>';
}
}
fclose($fp);
}
else
{
echo '<p>Fichier introuvable ! Lecture stoppée.</p>';
}
?>
</table>
<?
break;
}
?>
</body>
</html> |
Partager