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
Share on other sites

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
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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.