How can I strip HTML in a string using Perl?

后端 未结 3 1780
青春惊慌失措
青春惊慌失措 2021-02-04 12:59

Is there anyway easier than this to strip HTML from a string using Perl?

$Error_Msg =~ s|||ig;
$Error_Msg =~ s|||ig;
$Error_Msg =~ s|

        
3条回答
  •  半阙折子戏
    2021-02-04 13:19

    You should definitely have a look at the HTML::Restrict which allows you to strip away or restrict the HTML tags allowed. A minimal example that strips away all HTML tags:

    use HTML::Restrict;
    
    my $hr = HTML::Restrict->new();
    my $processed = $hr->process('i am bold'); # returns 'i am bold'
    

    I would recommend to stay away from HTML::Strip because it breaks utf8 encoding.

提交回复
热议问题