From add4f47ad7f89e43eb40f11d6378b82abd78164b Mon Sep 17 00:00:00 2001 From: adrien Date: Thu, 8 May 2025 14:33:31 +0200 Subject: [PATCH] fix nb mots --- dico.php | 4 +++- index.php | 18 +++++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/dico.php b/dico.php index b854846..0ce1368 100644 --- a/dico.php +++ b/dico.php @@ -32,7 +32,9 @@ function dico($longueur_max) { $mots = explode(CASE_NOIRE, $mot); $nb_mots = count($mots); $mot = implode("", $mots); - $definition .= "#$nb_mots"; + foreach($definitions as $i => $definition) { + $definitions[$i] = "$definition#$nb_mots"; + } } $dico[strlen($mot)][$mot] = $definitions; diff --git a/index.php b/index.php index ade7008..9ade4f0 100644 --- a/index.php +++ b/index.php @@ -53,11 +53,15 @@ if ($grille_valide) { $definition = $definitions[mt_rand(0, count($definitions) - 1)]; if (strpos($definition, "#") !== false) { [$definition, $nb_mots] = explode("#", $definition); - $definition .= " ($nb_mots mots)"; + $nb_mots = " ($nb_mots mots)"; + } else { + $nb_mots = ""; } if (strpos($definition, "@") !== false) { [$definition, $auteur] = explode("@", $definition); - $definition .= " $auteur"; + $auteur = " $auteur"; + } else { + $auteur = ""; } $definitions_horizontales[$y][] = $definition; } @@ -72,13 +76,17 @@ if ($grille_valide) { $definition = $definitions[mt_rand(0, count($definitions) - 1)]; if (strpos($definition, "#") !== false) { [$definition, $nb_mots] = explode("#", $definition); - $definition .= " ($nb_mots mots)"; + $nb_mots = " ($nb_mots mots)"; + } else { + $nb_mots = ""; } if (strpos($definition, "@") !== false) { [$definition, $auteur] = explode("@", $definition); - $definition .= " $auteur"; + $auteur = " $auteur"; + } else { + $auteur = ""; } - $definitions_verticales[$x][] = $definition; + $definitions_verticales[$x][] = $definition . $nb_mots . $auteur; } } }