Thread RegEx zum Tags entfernen arbeitet nicht richtig (4 answers)
Opened by DrWhiteLetter at 2005-08-07 22:37

renee
 2005-08-07 22:46
#57014 #57014
User since
2003-08-04
14371 Artikel
ModeratorIn
[Homepage] [default_avatar]
z.B.:
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#! /usr/bin/perl

use strict;
use warnings;
use Data::Dumper;
use HTML::Parser;

my $pa = qq~ <p>This is a bad try to display text then code
<pre>#! usr/bin/perl
use strict;
use warnings;

print "Hello World!";</pre>
and then plain text again</p>~;



my $parser = HTML::Parser->new(
start_h => [ \&_starttag, 'self, tagname, attr' ],
end_h => [ \&_endtag, 'self, tagname' ],
text_h => [ \&_text, 'self, dtext' ]
);

$parser->parse($pa);

sub _starttag {
my ($self, $tag, $attr) = @_;
$self->{'_body'} = 1 if ($tag eq 'body');
}

sub _endtag {
my ($self, $tag) = @_;
$self->{'_body'} = undef if ($tag eq 'body');
}

sub _text {
my ($self, $dtext) = @_;

$dtext =~ s/\A\s+//;
$dtext =~ s/\s+\z//;
return() unless ( length($dtext) > 0 and $dtext =~ /[^\s]/ );

if ( defined($self->{'_body'}) ) {
print $dtext," ";
}
}
OTRS-Erweiterungen (http://feature-addons.de/)
Frankfurt Perlmongers (http://frankfurt.pm/)
--

Unterlagen OTRS-Workshop 2012: http://otrs.perl-services.de/workshop.html
Perl-Entwicklung: http://perl-services.de/

View full thread RegEx zum Tags entfernen arbeitet nicht richtig