Current location: Hot Scripts Forums » Programming Languages » Perl » freeware code to strip HTML tags ?

freeware code to strip HTML tags ?

Reply
  #1 (permalink)  
Old 02-13-04, 01:08 PM
xgab xgab is offline
Newbie Coder
 
Join Date: Jun 2003
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
freeware code to strip HTML tags ?

Hi all, I would like to know if there is any freeware Perl code out there, similar to the PHP powerful function: strip_tags.

What I am needing is to strip HTML tags from email bodies. I have a Perl program that process emails that have been working for many years, but the HTML format in some email messages, is affecting other applications.

I need clean email messages texts.

Could anyone help me ?
Thank you in advance
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 03-03-04, 12:56 AM
Skeleton Man Skeleton Man is offline
Community Liaison
 
Join Date: Jun 2003
Location: Australia
Posts: 406
Thanks: 0
Thanked 0 Times in 0 Posts
Try this:

Code:
$code = "This<HTML>should<head>be<foo>HTML<bar>free</b>";
$code = preg_replace("/<.+?>/","",$code);

print $code;
Provided there aren't stupid things like incomplete tags ("<HTML", "<b", etc), this should be all you need to do.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 03-03-04, 12:51 PM
xgab xgab is offline
Newbie Coder
 
Join Date: Jun 2003
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Skeleton Man
Try this:

Code:
$code = "This<HTML>should<head>be<foo>HTML<bar>free</b>";
$code = preg_replace("/<.+?>/","",$code);

print $code;
Provided there aren't stupid things like incomplete tags ("<HTML", "<b", etc), this should be all you need to do.
Thank you for your reply.

Excuse me, I am a newbie... is your code Perl or PHP ?

It seems to be PHP...

I would need Perl code to strip html tags
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 03-03-04, 07:54 PM
Skeleton Man Skeleton Man is offline
Community Liaison
 
Join Date: Jun 2003
Location: Australia
Posts: 406
Thanks: 0
Thanked 0 Times in 0 Posts
My appologies, I had windows open from both PHP and Perl forums so I didn't see which I was posting to.

Perl version:

Code:
$code = "This<HTML>should<head>be<foo>HTML<bar>free</b>";
$code =~ s/<.+?>//g;

print "Content-type: text/plain\n\n";
print $code;
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 03-19-04, 02:23 PM
scorwin scorwin is offline
New Member
 
Join Date: Mar 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
This will strip all HTML tags:

##############################
use HTML::TreeBuilder;
use HTML::FormatText;

my $s; # the text out of which you wish to strip HTML

my $formatter = HTML::FormatText->new;
my $tree = HTML::TreeBuilder->new;
$tree->parse($s);
if ($tree) {
$formatter->format($tree);
$tree->delete; # DO NOT OMIT THIS STEP!
}
##############################

--Steve
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 04-19-04, 08:31 PM
xgab xgab is offline
Newbie Coder
 
Join Date: Jun 2003
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Skeleton Man
My appologies, I had windows open from both PHP and Perl forums so I didn't see which I was posting to.

Perl version:

Code:
$code = "This<HTML>should<head>be<foo>HTML<bar>free</b>";
$code =~ s/<.+?>//g;

print "Content-type: text/plain\n\n";
print $code;
Skeleton Man: Thank you so much for your help!!!! it worked!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Classified Ads skipper23 Perl 3 11-22-05 03:22 AM
formmail problem gscraper Perl 12 08-27-04 04:06 AM
removing specified html tags from text memon PHP 1 01-15-04 09:56 PM
Classified Ads skipper23 Perl 2 12-30-03 04:43 AM


All times are GMT -5. The time now is 02:55 AM.
vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.