Feb 13

perl清除html(格式)标签,  strip HTML tags

adminleon , 08:33 , 生活记录 , 评论(0) , 引用(0) , 阅读(68) , Via 本站原创 | |


  在google里搜索过,大概有以下方法:

http://www.programmingtalk.com/archive/index.php/t-6109.html

This will strip all HTML tags:

##############################
use HTML::TreeBuilder;
use HTML::FormatText;

my $s; # the text out of which you wish to strip HTML

my $formatter = HTML::FormatText->new;
my $tree = HTML::TreeBuilder->new;
$tree->parse($s);
if ($tree) {
$formatter->format($tree);
$tree->delete; # DO NOT OMIT THIS STEP!
}
##############################

或者
$code = "ThisshouldbeHTMLfree";
$code =~ s/<.+?>//g;

print "Content-type: text/plain\n\n";
print $code;


在google里输入perl striphtml 查询得来的. 在百度里搜索没什么结果.
有时间实践一下.

发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]