Gossamer Forum
Home : Products : Links 2.0 : Customization :

Mail-A-Friend

Quote Reply
Mail-A-Friend
I wrote a Mod that mails the record to (multiple) friends. The only problem is that html tags are send in the mail. (The html-tags are part of the record and are entered by users. There allowed to do this!)

Is there a routine that would remove alll html-tags? So I can modify my line_wrap to remove all html.

Something like:

sub linewrap {
# --------------------------------------------------------
# Wraps a line into 60 char chunks.

my $line = shift; defined $line or return '';
$line = &remove_all_html_tags($line);
my @data = split /\t/, $line;


Quote Reply
Re: Mail-A-Friend In reply to
s///g;

while ( s/<(?!--)[^'">]*"[^"]*"/</g
or s/<(?!--)[^'">]*'[^']*'/</g) {};

s/<(?!--)[^">]*>//g;


Ugh....the forum strips out that first bit of code...... (s///g;) - it should be this in the middle WITHOUT the spaces.....

<! - - .*? - - >

SO... s/THEN THE BIT ABOVE//g;

Paul Wilson.
http://www.wiredon.net/gt/
http://www.perlmad.com/
Quote Reply
Re: Mail-A-Friend In reply to
Paul,

I don't need to remove because only selected members (edittors) can add records; but currently there allowed to use <b></b> and
signs. So I would like to remove 'normal' html-tags

Do I then need to use the following? I know you just had a crash-course reg. exp Wink

sub linewrap {
# --------------------------------------------------------
# Wraps a line into 60 char chunks.

my $line = shift; defined $line or return '';
$line =~ /CODE//g; # remove html by PaulWilson
my @data = split /\t/, $line;
my $columns = 60;



CODE: s/<(?!--)[^">]*>//g;


Quote Reply
Re: Mail-A-Friend In reply to
hi,

yes that should be fine - the other code was for removing things like <font name="arial">....etc.......

So that code you have there should be fine for just <b> </b> etc...

Paul Wilson.
http://www.wiredon.net/gt/
http://www.perlmad.com/
Quote Reply
Re: Mail-A-Friend In reply to
Thanks; but In the meanwhile I found the following thread with an other code.

Add code: $value =~ s/<([^>]|\n)*>//g; # Remove HTML

This because the code above would only remove the end tags like </script> </b>


URL: http://www.gossamer-threads.com/...ew=&sb=&vc=1

Quote Reply
Re: Mail-A-Friend In reply to
Hi,

This....

s/<(?!--)[^">]*>//g;


Removes html comments, speech marks and brackets < >

This.......

$value =~ s/<([^>]|\n)*>//g;

only removes brackets but im not sure about this |\n - it is obviously something to do with new lines.

Paul Wilson.
http://www.wiredon.net/gt/
http://www.perlmad.com/
Quote Reply
Re: Mail-A-Friend In reply to
Oeps; you where too quick!

Instead of posting a new message I editted the above one. (I know I shouldn't; but I found something out in the meanwhile) Anyway: Read the message above :-)

Quote Reply
Re: Mail-A-Friend In reply to
Oeps; you where too quick!

Instead of posting a new message I editted the above one. (I know I shouldn't; but I found something out in the meanwhile) Anyway: Read the message above :-)

I tested the subs with this routine: (very handy)

#!/usr/bin/perl

$file = "/users/www/data/index.html";

open FILE, "$file";
while (<FILE>) { $html .= $_; }
close FILE;

print "Content-type: text/plain\n\n";
$html =~ s/<([^>]|\n)*>//g;
#$html =~ s/<(?!--)[^">]*>//g;
print "$html";



Quote Reply
Re: Mail-A-Friend In reply to
...and the results?

Paul Wilson.
http://www.wiredon.net/gt/
http://www.perlmad.com/
Quote Reply
Re: Mail-A-Friend In reply to
As I said: "Anyway: Read the message above :-)"

- Your code only removed </b> and </script> not <b> and <script>. So only the end-tags!
- The other code worked like a charm :-)