Leser: 17
1 2 3
my $path = $ENV{HTTP_PATH_INFO}; my $regex_img = qr#<img(\b[^>]*)?src="(?<!https:\/\/|http:\/\/|ftp:\/\/)([^"]*)"(\b?[^>]*)?>#; $body =~ s#$regex_img#<img$1src="$path/$2"$3>#igm;
1 2 3 4 5 6 7 8 9 10 11 12 13 14
my $regex_img = qr{<img([^>]+)src="([^"]+)"([^>]+)>}; $body =~ s#$regex_img#img_parse($1, $2, $3)#igme; sub img_parse { my $a = shift; my $img_url = shift; my $b = shift; if($img_url =~ m/^(https?|ftp):\/\//) { return '<img'.$a.'src="'.$img_url.'"' . $b . '>'; } else { return '<img'.$a.'src="'.$path.'/'.$img_url.'"' . $b . '>'; } }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
my $regex_img = qr{<img([^>]+)?src="([^"]+)?"([^>]+)?>}; $body =~ s#$regex_img#img_parse($1, $2, $3)#igme; my $regex_excl = qr{^(https?|ftp):\/\/}; sub img_parse { my $a = shift; my $img_url = shift; my $b = shift; if($img_url =~ m/$regex_excl/) { return '<img'.$a.'src="'.$img_url.'"' . $b . '>'; } else { $img_url =~ s/^\///; return '<img'.$a.'src="'.$path.'/'.$img_url.'"' . $b . '>'; } }
2010-11-09T18:30:56 GwenDragonArrgh, sowas von unzumutbar lahm ist Perl 5.8 bei den Regex-Ersetzungen.