Thread Tags finden
(21 answers)
Opened by Froschpopo at 2008-04-13 18:34
suchst du sowas?
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 #!/usr/bin/perl use strict; use warnings; my $text = "Dies ist [fett]ein fetter Text[/fett]."; my %tags = ( fett => '<strong>%s</strong>', kursiv => '<span style="font-style:italic">%s</span>' ); # entweder so: my $t=$text; for my $key (keys(%tags)) { $t=~s|\[$key\](.+?)\[/$key\]|sprintf($tags{$key},$1)|egs; } print "$t\n"; #oder so: $t=$text; $t=~s|\[([^\[\]\W]+)\](.+?)\[/\1]|replace($1,$2)|egs; print "$t\n"; sub replace { return sprintf($tags{shift(@_)},shift(@_)) } |