Par défaut, la fonction nl2br replace ”\n” par « <br />\n» dans une chaîne de caractères. Voici une fonction qui permet d’éviter le retour chariot désagréable
1 2 3 4 5 6 7 | // modification de nl2br() function nlToBr($text) { $text = str_replace("\r", '', $text); $text = str_replace("\n", '<br />', $text); return $text; } |
Voici la fonction inverse:
1 2 3 4 5 6 | // inverse de nlToBr() function brToNl($text){ $text = str_replace(array("\r", "\n"), '', $text); $text = str_replace(array('<br>', '<br />'), "\n", $text); return $text; } |

