note 10384 added to nl2br

From: Date: Sun, 31 Dec 2000 00:46:14 +0000
Subject: note 10384 added to nl2br
Groups: php.notes 
Request: Send a blank email to php-notes+get-9288@lists.php.net to get a copy of this message
Ah, looks like someone erased my other example. Well, here it is again. Usage of nl2br to display data on a web page after retrieving from a database. Usually, the data strips all line breaks and the text runs together. nl2br will put the line breaks back in. Example, say your variable is $theText and this variable holds a couple of paragraphis of info. To display it properly with line breaks, use this format; $theText = nl2br($theText); $theText = ereg_replace("\n", "", $theText); $theText = ereg_replace("\r", "", $theText); $theText = ereg_replace("'", "'", $theText); PRINT "$theText"; ----- Thus, the output will include line breaks. Also note the following line from above $theText = ereg_replace("'", "'", $theText); Which replaces the single quote with the character code. Otherwise, all text after a single quote will be lost. http://www.php.net/manual/function.nl2br.php

« previous php.notes (#9288) next »