normalize($sample); } } private function normalize(string $value): string { $output = $this->fromUt8ToPlainText($value); $output = $this->safelyRemoveEmptyLines($output); return $output; } private function fromUt8ToPlainText(string $value): string { // * Supprimer les balises $output = strip_tags($value); // * Convertir les entités html (ex: & devient &) $output = html_entity_decode($output, ENT_QUOTES | ENT_HTML5, 'UTF-8'); return $output; } private function safelyRemoveEmptyLines(string $value): string { // * Remplace les lignes ne contenant que des espaces/tabs par une chaîne vide $result = preg_replace('/^[\s\t]*[\r\n]+/m', '', $value); // * Remplace les sauts de lignes avec un `\n` unique $result = preg_replace('/\R/', "\n", $result); return $result ?? $value; } }