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, Link to comment https://forums.phpfreaks.com/topic/94276-converting-html-to-text-using-strip_tags/ Share on other sites More sharing options...
discomatt Posted March 4, 2008 Share Posted March 4, 2008 try nl2br(strip_tags($email)) Link to comment https://forums.phpfreaks.com/topic/94276-converting-html-to-text-using-strip_tags/#findComment-482894 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 Link to comment https://forums.phpfreaks.com/topic/94276-converting-html-to-text-using-strip_tags/#findComment-482916 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 Link to comment https://forums.phpfreaks.com/topic/94276-converting-html-to-text-using-strip_tags/#findComment-482935 Share on other sites More sharing options...
coderb Posted March 4, 2008 Author Share Posted March 4, 2008 thanks for your help, much appreciated. Link to comment https://forums.phpfreaks.com/topic/94276-converting-html-to-text-using-strip_tags/#findComment-483006 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.