Fix: [ bug #253 ] Non UTF-8 characters in CSV exports

This commit is contained in:
Laurent Destailleur 2011-12-21 16:10:11 +01:00
parent b75688f76b
commit 721c9a6f5b
2 changed files with 8 additions and 7 deletions

View File

@ -3524,12 +3524,13 @@ function picto_required()
*
* @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

View File

@ -171,7 +171,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);
}
@ -206,7 +206,6 @@ class ExportCsv extends ModeleExports
{
$alias=str_replace(array('.','-'),'_',$code);
if (empty($alias)) dol_print_error('','Bad value for field with key='.$code.'. Try to redefine export.');
$newvalue=$outputlangs->convToOutputCharset($objp->$alias);
// Translation newvalue
@ -215,7 +214,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++;
@ -251,14 +250,15 @@ class ExportCsv extends ModeleExports
* Clean a cell to respect rules of CSV file cells
*
* @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);