Jump to content

converting html to text using strip_tags


coderb

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.