header
 
     
 
pixel
pixel pixel

Converting ASCII line returns to HTML line breaks

If your webpage is displaying text from a database or HTML form where the text may contain carriage returns, your carriage returns won't be displayed in a HTML page. Consequently, all your paragraphs will be merged into a single paragraph. You need to convert all ASCII line breaks into HTML link breaks using the in-built PHP function nl2br():
<?php
$textdata 
"here is
a bit of text
to break into separate lines"
;
echo 
nl2br$textdata );
?>

Unhelpful Helpful Rating 4.0 (score out of 5, no. of ratings: 11)
Post a Comment
Name
Email
(optional)
Comment
RatingUnhelpful Helpful
Security Image* (this is just to prevent spam submissions)
Security Image