Converting HTML to text

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nutkenz
Forum Contributor
Posts: 155
Joined: Tue Jul 19, 2005 12:25 pm

Converting HTML to text

Post by nutkenz »

I'm looking for a class that does this so I can easily make multipart TEXT/HTML e-mails. I haven't had much luck so far finding a PHP class that does this, although there are some windows applications for it. Does anyone happen to know of such a class?
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

what do you mean converting HTML to TEXT.

you mean you want to convert the HTML entities into text representations?

if so, have a look at htmlentities()
nutkenz
Forum Contributor
Posts: 155
Joined: Tue Jul 19, 2005 12:25 pm

Post by nutkenz »

I didn't mean simply removing HTML tags, but replacing them with a text-layout.

For example:

<h1>Title</h1>
<p>Bla blablabla blabla</p>
<hr>

Would become something like this:

TITLE
====

Bla blablabla blabla

------------------------------------
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

use preg_replace() to replace key text tags (like h1, p, etc...), strip the remaining tags, then change your headers to text/plain and fine tune from there.

OR you could use XSLT to TRANSFORM your document!
gavin1996
Forum Newbie
Posts: 22
Joined: Tue Jan 30, 2007 8:30 pm

Post by gavin1996 »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


This function can delete all HTML tag

[syntax="javascript"]function CheckForm(form){
  form.content.value=IframeID.document.body.innerHTML;    
  //alert(form.content.value);
  var s = form.content.value;
  s = s.replace(/(<(.[^>]*)>)|(&nbsp;)/g,"");
  s = s.replace(/[\r][\n]/g,"");
  //alert("*" + s + "*");
  //alert(s.length);
  MessageLength=IframeID.document.body.innerHTML.length;
  if(MessageLength<2){alert("so short");return false;}
  if(MessageLength>50000){alert("so long");return false;}  
  document.editfrm.submit.disabled = true;
  return true;
}
</script>
more tutorial visit: http://www.website-tutorial.net/


feyd | Please use[/syntax]

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Post Reply