From ba5adb29d8012eb1d06c27c0623595400e173a93 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 21 Dec 2011 16:15:21 +0100 Subject: [PATCH] Fix: [ bug #253 ] Non UTF-8 characters in CSV exports --- .../includes/modules/export/export_csv.modules.php | 14 ++++++++------ htdocs/lib/functions.lib.php | 5 +++-- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/htdocs/includes/modules/export/export_csv.modules.php b/htdocs/includes/modules/export/export_csv.modules.php index 6f6c7ed2a1b..824e7b3fd40 100644 --- a/htdocs/includes/modules/export/export_csv.modules.php +++ b/htdocs/includes/modules/export/export_csv.modules.php @@ -166,7 +166,7 @@ class ExportCsv extends ModeleExports foreach($array_selected_sorted as $code => $value) { $newvalue=$outputlangs->transnoentities($array_export_fields_label[$code]); - $newvalue=$this->csv_clean($newvalue); + $newvalue=$this->csv_clean($newvalue,$outputlangs->charset_output); fwrite($this->handle,$newvalue.$this->separator); } @@ -207,7 +207,7 @@ class ExportCsv extends ModeleExports $newvalue=$outputlangs->transnoentities($reg[1]); } - $newvalue=$this->csv_clean($newvalue); + $newvalue=$this->csv_clean($newvalue,$outputlangs->charset_output); fwrite($this->handle,$newvalue.$this->separator); $this->col++; @@ -237,15 +237,17 @@ class ExportCsv extends ModeleExports /** * Clean a cell to respect rules of CSV file cells - * @param newvalue String to clean - * @return string Value cleaned + * + * @param string $newvalue String to clean + * @param string $charset Output character set + * @return string Value cleaned */ - function csv_clean($newvalue) + function csv_clean($newvalue, $charset) { $addquote=0; // Rule Dolibarr: No HTML - $newvalue=dol_string_nohtmltag($newvalue); + $newvalue=dol_string_nohtmltag($newvalue,1,$charset); // Rule 1 CSV: No CR, LF in cells $newvalue=str_replace("\r",'',$newvalue); diff --git a/htdocs/lib/functions.lib.php b/htdocs/lib/functions.lib.php index 88f18b90abc..aff508e2a06 100644 --- a/htdocs/lib/functions.lib.php +++ b/htdocs/lib/functions.lib.php @@ -3499,12 +3499,13 @@ function picto_required() * Clean a string from all HTML tags and entities * @param StringHtml String to clean * @param removelinefeed Replace also all lines feeds by a space + * @param pagecodeto Encoding of input string * @return string String cleaned */ -function dol_string_nohtmltag($StringHtml,$removelinefeed=1) +function dol_string_nohtmltag($StringHtml,$removelinefeed=1,$pagecodeto='UTF-8') { $pattern = "/<[^>]+>/"; - $temp = dol_entity_decode($StringHtml); + $temp = dol_entity_decode($StringHtml,$pagecodeto); $temp = preg_replace($pattern,"",$temp); // Supprime aussi les retours