Thread BBCode URL Teile filtern (8 answers)
Opened by John at 2011-05-05 20:09

pq
 2011-05-06 22:05
#148305 #148305
User since
2003-08-04
12208 Artikel
Admin1
[Homepage]
user image
Code (perl): (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
use Parse::BBCode;
use URI::Find;
my $finder = URI::Find->new(sub {
    my ($url) = @_;
    my $title = $url;
    if (length($title) > $max_url) {
        $title = substr($title, 0, $max_url) . "...";
    }
    my $escaped = Parse::BBCode::escape_html($url);
    my $escaped_title = Parse::BBCode::escape_html($title);
    my $href = qq{<a href="$escaped">$escaped_title</a>};
    return $href;
});

my $p = Parse::BBCode->new({
    tags => {
        # parsen von text ausserhalb/innerhalb von tags
        '' => sub {
                my $e = $_[2];
                my $count = $finder->find(\$e, $escape);
                $e =~ s/\r?\n|\r/<br>\n/g;
                $e
        },
        # parsen von [youtube] tags
        youtube => # code aus meinem anderen posting
    },
});

ungetestet
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. -- Damian Conway in "Perl Best Practices"
lesen: Wiki:Wie frage ich & perlintro Wiki:brian's Leitfaden für jedes Perl-Problem

View full thread BBCode URL Teile filtern