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

02-13-04, 12:08 PM
|
|
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
|
|

03-02-04, 11:56 PM
|
|
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.
|
|

03-03-04, 11:51 AM
|
|
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
|
|

03-03-04, 06:54 PM
|
|
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;
|
|

03-19-04, 01:23 PM
|
|
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
|
|

04-19-04, 07:31 PM
|
|
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!
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
|
All times are GMT -5. The time now is 02:23 PM. |
|