-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMotsContenant_Verif.php
More file actions
67 lines (58 loc) · 2.65 KB
/
Copy pathMotsContenant_Verif.php
File metadata and controls
67 lines (58 loc) · 2.65 KB
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
<?php
session_start();
$resultats = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$serieLettres = mb_strtoupper(trim($_POST['serieLettres']));
$resultats = '';
if (preg_match('/^[A-ZÀ-ÖØ-Ý]{3,}$/u', $serieLettres)) {
$resultats .= "<HR>";
$cheminFichierMots = 'liste_francais.txt';
if (!isset($_SESSION['liste_francais'])) {
$mots = file($cheminFichierMots, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$_SESSION['liste_francais'] = $mots;
}
else
$mots = $_SESSION['liste_francais'];
foreach ($mots as &$mot) {
$mot = mb_convert_encoding($mot, 'UTF-8', 'ISO-8859-1');
}
$motsTrouves = array_filter($mots, function ($mot) use ($serieLettres) {
return mb_stripos($mot, $serieLettres) !== false;
});
if (empty($motsTrouves)) {
$resultats .= '<p>Aucun mot trouvé contenant ' . $serieLettres . ' parmi ' . number_format(count($mots), 0, ',', ' ') . ' mots</p>';
} else {
$resultats .= count($motsTrouves) . ' mots trouvés parmi ' . number_format(count($mots), 0, ',', ' ') . ' contenant ' . $serieLettres;
$resultats .= '<ul>';
foreach ($motsTrouves as $mot) {
$resultats .= "<li>" . str_replace(mb_strtolower($serieLettres), '<B>' . mb_strtolower($serieLettres) . '</B>', $mot) . "</li>";
}
$resultats .= '</ul>';
}
$resultats .= "<HR>";
$cheminFichierMots = 'DEM-1_1.txt';
if (!isset($_SESSION['DEM-1_1'])) {
$mots = file($cheminFichierMots, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$_SESSION['DEM-1_1'] = $mots;
}
else
$mots = $_SESSION['DEM-1_1'];
$motsTrouves = array_filter($mots, function ($mot) use ($serieLettres) {
return mb_stripos($mot, $serieLettres) !== false;
});
if (empty($motsTrouves)) {
$resultats .= '<p>Aucun mot trouvé contenant ' . $serieLettres . ' parmi ' . number_format(count($mots), 0, ',', ' ') . ' mots</p>';
} else {
$resultats .= count($motsTrouves) . ' mots trouvés parmi ' . number_format(count($mots), 0, ',', ' ') . ' contenant ' . $serieLettres;
$resultats .= '<ul>';
foreach ($motsTrouves as $mot) {
$resultats .= "<li>" . str_replace(mb_strtolower($serieLettres), '<B>' . mb_strtolower($serieLettres) . '</B>', $mot) . "</li>";
}
$resultats .= '</ul>';
}
} else {
$resultats .= '<p>La série de lettres spécifiée n\'est pas valide.</p>';
}
}
echo $resultats;
?>