diff --git a/htdocs/core/tpl/freeproductline_view.tpl.php b/htdocs/core/tpl/freeproductline_view.tpl.php index 15defba59d8..7beb197f139 100644 --- a/htdocs/core/tpl/freeproductline_view.tpl.php +++ b/htdocs/core/tpl/freeproductline_view.tpl.php @@ -37,14 +37,14 @@ $discount->fetch($line->fk_remise_except); echo ' - '.$langs->transnoentities("DiscountFromDeposit",$discount->getNomUrl(0)); } else { - echo ' - '.nl2br($line->description); + echo ' - '.dol_nl2br($line->description,1,true); } } } else { if (! empty($line->fk_parent_line)) echo img_picto('', 'rightarrow'); if ($type==1) $text = img_object($langs->trans('Service'),'service'); else $text = img_object($langs->trans('Product'),'product'); - echo $text.' '.nl2br($line->description); + echo $text.' '.dol_nl2br($line->description,1,true); // Show range print_date_range($line->date_start,$line->date_end); } ?> diff --git a/htdocs/lib/functions.lib.php b/htdocs/lib/functions.lib.php index 456dd8c54de..e6eda3ef5fa 100644 --- a/htdocs/lib/functions.lib.php +++ b/htdocs/lib/functions.lib.php @@ -3064,8 +3064,8 @@ function dol_nl2br($stringtoencode,$nl2brmode=0,$forxml=false) } else { - $ret=str_replace("\r","",$stringtoencode); - $ret=str_replace("\n",($forxml?'
':'
'),$ret); + $ret=preg_replace('/(
||)\s*(\r\n|\r|\n)+/i',($forxml?'
':'
'),$stringtoencode); + $ret=preg_replace('/([^])+(\r\n|\r|\n)+/i',($forxml?'
':'
'),$ret); return $ret; } } @@ -3087,7 +3087,8 @@ function dol_htmlentitiesbr($stringtoencode,$nl2brmode=0,$pagecodefrom='UTF-8') { if (dol_textishtml($stringtoencode)) { - $newstring=preg_replace('//i','
',$stringtoencode); // Replace "
" by "
". It's same and avoid pb with FPDF. + $newstring=preg_replace('/([^])+(\r\n|\r|\n)+/i',($forxml?'
':'
'),$stringtoencode); // Don't replace if in list + $newstring=preg_replace('//i','
',$newstring); // Replace "
" by "
". It's same and avoid pb with FPDF. $newstring=preg_replace('/
$/i','',$newstring); // Replace "
" by "
". It's same and avoid pb with FPDF. $newstring=strtr($newstring,array('&'=>'__and__','<'=>'__lt__','>'=>'__gt__','"'=>'__dquot__')); $newstring=dol_htmlentities($newstring,ENT_COMPAT,$pagecodefrom); // Make entity encoding @@ -3270,6 +3271,7 @@ function dol_textishtml($msg,$option=0) elseif (preg_match('/
|
|)\s*/i", + "/(\r\n|\r|\n)/" + ); + $replacements = array( + PHP_EOL, + $line_break + ); + $string = preg_replace($patterns, $replacements, $string); + return $string; +} + ?> \ No newline at end of file diff --git a/htdocs/product/fiche.php b/htdocs/product/fiche.php index a1d862f818f..5a6628f55f8 100644 --- a/htdocs/product/fiche.php +++ b/htdocs/product/fiche.php @@ -1099,7 +1099,7 @@ if ($id || $ref) print ''; // Description - print ''.$langs->trans("Description").''.nl2br($product->description).''; + print ''.$langs->trans("Description").''.dol_nl2br($product->description,1,true).''; // Nature if($product->type!=1)