genics Posted March 28, 2007 Share Posted March 28, 2007 Hi folks, A user inputs a news article into the database and then I echo it out onto the front end. However line breaks aren't kept and the text string is stripped of spacing. So the user inputs into the textbox Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec tincidunt. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Donec risus. Nullam faucibus. In hac habitasse platea dictumst. Duis quis sem. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae. However it is echo'd out as this: Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec tincidunt. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Donec risus. Nullam faucibus. In hac habitasse platea dictumst. Duis quis sem. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae. How do I solve this problem? Thanks Link to comment https://forums.phpfreaks.com/topic/44686-solved-line-breaks/ Share on other sites More sharing options...
papaface Posted March 28, 2007 Share Posted March 28, 2007 try: echo "<pre>"; echo $string; echo "</pre>"; Link to comment https://forums.phpfreaks.com/topic/44686-solved-line-breaks/#findComment-217004 Share on other sites More sharing options...
Lumio Posted March 28, 2007 Share Posted March 28, 2007 Better: echo nl2br($string); Link to comment https://forums.phpfreaks.com/topic/44686-solved-line-breaks/#findComment-217015 Share on other sites More sharing options...
genics Posted March 28, 2007 Author Share Posted March 28, 2007 Thanks guys This is my final code: $string = bbcode_format ($news_content); echo nl2br($string); Is this the best way to get the desired result? Link to comment https://forums.phpfreaks.com/topic/44686-solved-line-breaks/#findComment-217018 Share on other sites More sharing options...
Lumio Posted April 9, 2007 Share Posted April 9, 2007 Maybe $string = nl2br(bbcode_format($news_content); is better? I don't know Link to comment https://forums.phpfreaks.com/topic/44686-solved-line-breaks/#findComment-225215 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.