ProgrammingTalk


Welcome to the ProgrammingTalk forums. We are a programming, coding, and design oriented community dedicated to helping out with all different types of programming questions and languages.

You are currently viewing our board as a guest which gives you very limited access to view discussions and access our other features. In order to gain full access to this board, we require you to register. Registration is absolutely free and very easy to accomplish, simply click the link above to begin. If you have already registered with us, all you have to do is login.

If you have any problems with the registration process or your account login, please don't hesitate to contact Support.
Go Back   ProgrammingTalk > Programming Languages > Perl
Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 02-13-04, 12:08 PM
xgab xgab is offline
Newbie Coder
 
Join Date: Jun 2003
Posts: 18
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
Reply With Quote
  #2  
Old 03-02-04, 11:56 PM
Skeleton Man Skeleton Man is offline
Community Liaison
 
Join Date: Jun 2003
Location: Australia
Posts: 406
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.
Reply With Quote
  #3  
Old 03-03-04, 11:51 AM
xgab xgab is offline
Newbie Coder
 
Join Date: Jun 2003
Posts: 18
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
Reply With Quote
  #4  
Old 03-03-04, 06:54 PM
Skeleton Man Skeleton Man is offline
Community Liaison
 
Join Date: Jun 2003
Location: Australia
Posts: 406
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;
Reply With Quote
  #5  
Old 03-19-04, 01:23 PM
scorwin scorwin is offline
New Member
 
Join Date: Mar 2004
Posts: 1
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
Reply With Quote
  #6  
Old 04-19-04, 07:31 PM
xgab xgab is offline
Newbie Coder
 
Join Date: Jun 2003
Posts: 18
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!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

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

Advertisement:

All times are GMT -5. The time now is 02:23 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright © 1998-2008 ProgrammingTalk. All Rights Reserved. A division of iNET Interactive
Related iNET Interactive Sites:
Web Hosting Talk | Hot Scripts | OC Forums | Mac-Forums