Page 1 of 1

Converting HTML to text

Posted: Tue Jan 30, 2007 11:59 am
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?

Posted: Tue Jan 30, 2007 12:06 pm
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()

Posted: Tue Jan 30, 2007 12:14 pm
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

------------------------------------

Posted: Tue Jan 30, 2007 2:28 pm
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!

Posted: Wed Jan 31, 2007 3:32 am
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]