coderb Posted March 4, 2008 Share Posted March 4, 2008 Hi All, I've built a email preview page which displays either html email or the text version of the same, depending on user choice. I use echo strip_tags($email) to display the text version. But in the browser window, all the text is displayed as a string of words, losing any line breaks. When I look at the page source of this page, all line breaks are still correct. So why is the browser suppressing all the line breaks, tabs etc? And how can I retain them? thanks for any help, Quote Link to comment Share on other sites More sharing options...
discomatt Posted March 4, 2008 Share Posted March 4, 2008 try nl2br(strip_tags($email)) Quote Link to comment Share on other sites More sharing options...
coderb Posted March 4, 2008 Author Share Posted March 4, 2008 great. thanks discomatt, that worked. just one more question on that, my text version has extra line breaks that I don't want. is there a way to strip down all extra line breaks? I tried trim(nl2br(strip_tags($email))); but no change. cheers Quote Link to comment Share on other sites More sharing options...
discomatt Posted March 4, 2008 Share Posted March 4, 2008 Well, this gets tricky as php has a hard time finding out which are extra, and which should be there... easier bet is to use str_replace("\r\n\r\n", "\r\n", $input) for win and str_replace("\n\n", "\n", $input) for *nix generated files Quote Link to comment Share on other sites More sharing options...
coderb Posted March 4, 2008 Author Share Posted March 4, 2008 thanks for your help, much appreciated. Quote Link to comment 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.