JSHINER Posted September 24, 2007 Share Posted September 24, 2007 When I use the following: <?php echo htmlentities(stripslashes($page['listing']['desc'])); ?> It displays the text as: ---- Text. Line 2. Line 3 ---- Which is INCORRECT When I use the following in a text area: <textarea name="desc"><?php echo htmlentities(stripslashes($page['listing']['desc'])); ?></textarea> It displays the text as: ---- Text. Line 2. Line 3. ---- Which is CORRECT. Any ideas why this is happening? Quote Link to comment https://forums.phpfreaks.com/topic/70462-solved-spacing-line-breaks-help/ Share on other sites More sharing options...
HuggieBear Posted September 24, 2007 Share Posted September 24, 2007 $page['listing']['desc'] contains some "\n" characters (newline) which aren't displayed in HTML, but are in <textarea> tag. Regards Huggie Quote Link to comment https://forums.phpfreaks.com/topic/70462-solved-spacing-line-breaks-help/#findComment-353996 Share on other sites More sharing options...
JSHINER Posted September 24, 2007 Author Share Posted September 24, 2007 How do I get them to display in the HTML? str_replace /n with <br> ? Quote Link to comment https://forums.phpfreaks.com/topic/70462-solved-spacing-line-breaks-help/#findComment-354005 Share on other sites More sharing options...
JSHINER Posted September 24, 2007 Author Share Posted September 24, 2007 Solved using: str_replace("\n", '<br />', htmlentities(stripslashes($page['listing']['desc']))); Quote Link to comment https://forums.phpfreaks.com/topic/70462-solved-spacing-line-breaks-help/#findComment-354007 Share on other sites More sharing options...
HuggieBear Posted September 24, 2007 Share Posted September 24, 2007 How do I get them to display in the HTML? Use the function nl2br() Regards Huggie Quote Link to comment https://forums.phpfreaks.com/topic/70462-solved-spacing-line-breaks-help/#findComment-354067 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.