From 3937368ca3298a281022c9f3dea1e1a80fe772e5 Mon Sep 17 00:00:00 2001 From: Dasc3er Date: Fri, 10 Sep 2021 15:39:06 +0200 Subject: [PATCH] Fix gestione caratteri speciali in Fattura Elettronica --- plugins/exportFE/src/Validator.php | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/plugins/exportFE/src/Validator.php b/plugins/exportFE/src/Validator.php index a1ad8491c..6f4fd42dd 100755 --- a/plugins/exportFE/src/Validator.php +++ b/plugins/exportFE/src/Validator.php @@ -631,20 +631,26 @@ class Validator // Formattazione testo elseif ($info['type'] == 'string' || $info['type'] == 'normalizedString') { - $output = replace(html_entity_decode($output), [ - '&' => '&', - '"' => '"', - "'" => ''', - '<' => '<', - '>' => '>', + /** + * Sostituzione dei caratteri speciali del linguaggio. + * + * @source https://stackoverflow.com/a/3373364 + */ + $replace_chars = ['Š' => 'S', 'š' => 's', 'Ž' => 'Z', 'ž' => 'z', 'À' => 'A', 'Á' => 'A', 'Â' => 'A', 'Ã' => 'A', 'Ä' => 'A', 'Å' => 'A', 'Æ' => 'A', 'Ç' => 'C', 'È' => 'E', 'É' => 'E', 'Ê' => 'E', 'Ë' => 'E', 'Ì' => 'I', 'Í' => 'I', 'Î' => 'I', 'Ï' => 'I', 'Ñ' => 'N', 'Ò' => 'O', 'Ó' => 'O', 'Ô' => 'O', 'Õ' => 'O', 'Ö' => 'O', 'Ø' => 'O', 'Ù' => 'U', 'Ú' => 'U', 'Û' => 'U', 'Ü' => 'U', 'Ý' => 'Y', 'Þ' => 'B', 'ß' => 'Ss', 'à' => 'a', 'á' => 'a', 'â' => 'a', 'ã' => 'a', 'ä' => 'a', 'å' => 'a', 'æ' => 'a', 'ç' => 'c', 'è' => 'e', 'é' => 'e', 'ê' => 'e', 'ë' => 'e', 'ì' => 'i', 'í' => 'i', 'î' => 'i', 'ï' => 'i', 'ð' => 'o', 'ñ' => 'n', 'ò' => 'o', 'ó' => 'o', 'ô' => 'o', 'õ' => 'o', 'ö' => 'o', 'ø' => 'o', 'ù' => 'u', 'ú' => 'u', 'û' => 'u', 'ý' => 'y', 'þ' => 'b', 'ÿ' => 'y']; + $output = replace($output, $replace_chars); - // Caratteri personalizzati + // Sostituzione tag e contenuti specifici per XML + $output = htmlspecialchars($output, ENT_NOQUOTES | ENT_XML1 | ENT_SUBSTITUTE, 'UTF-8', false); + + // Sostituzione per caratteri personalizzati + $output = replace($output, [ '€' => 'euro', '—' => '-', '…' => '...', + '~' => '-', ]); - $output = preg_replace('/[^ -~òèéàùì°]+/', ' ', $output); + $output = preg_replace('/[[:^print:]]/', ' ', utf8_decode($output)); } // Riduzione delle dimensioni