{
    "mode": "perldoc",
    "parameter": "HTML::Filter",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/HTML%3A%3AFilter/json",
    "generated": "2026-06-12T23:15:26Z",
    "synopsis": "require HTML::Filter;\n$p = HTML::Filter->new->parsefile(\"index.html\");",
    "sections": {
        "NAME": {
            "content": "HTML::Filter - Filter HTML text through the parser\n",
            "subsections": []
        },
        "NOTE": {
            "content": "This module is deprecated. The \"HTML::Parser\" now provides the functionally of \"HTML::Filter\"\nmuch more efficiently with the \"default\" handler.\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "require HTML::Filter;\n$p = HTML::Filter->new->parsefile(\"index.html\");\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "\"HTML::Filter\" is an HTML parser that by default prints the original text of each HTML element\n(a slow version of cat(1) basically). The callback methods may be overridden to modify the\nfiltering for some HTML elements and you can override output() method which is called to print\nthe HTML text.\n\n\"HTML::Filter\" is a subclass of \"HTML::Parser\". This means that the document should be given to\nthe parser by calling the $p->parse() or $p->parsefile() methods.\n",
            "subsections": []
        },
        "EXAMPLES": {
            "content": "The first example is a filter that will remove all comments from an HTML file. This is achieved\nby simply overriding the comment method to do nothing.\n\npackage CommentStripper;\nrequire HTML::Filter;\n@ISA=qw(HTML::Filter);\nsub comment { }  # ignore comments\n\nThe second example shows a filter that will remove any <TABLE>s found in the HTML file. We\nspecialize the start() and end() methods to count table tags and then make output not happen\nwhen inside a table.\n\npackage TableStripper;\nrequire HTML::Filter;\n@ISA=qw(HTML::Filter);\nsub start\n{\nmy $self = shift;\n$self->{tableseen}++ if $[0] eq \"table\";\n$self->SUPER::start(@);\n}\n\nsub end\n{\nmy $self = shift;\n$self->SUPER::end(@);\n$self->{tableseen}-- if $[0] eq \"table\";\n}\n\nsub output\n{\nmy $self = shift;\nunless ($self->{tableseen}) {\n$self->SUPER::output(@);\n}\n}\n\nIf you want to collect the parsed text internally you might want to do something like this:\n\npackage FilterIntoString;\nrequire HTML::Filter;\n@ISA=qw(HTML::Filter);\nsub output { push(@{$[0]->{fhtml}}, $[1]) }\nsub filteredhtml { join(\"\", @{$[0]->{fhtml}}) }\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "HTML::Parser\n",
            "subsections": []
        },
        "COPYRIGHT": {
            "content": "Copyright 1997-1999 Gisle Aas.\n\nThis library is free software; you can redistribute it and/or modify it under the same terms as\nPerl itself.\n",
            "subsections": []
        }
    },
    "summary": "HTML::Filter - Filter HTML text through the parser",
    "flags": [],
    "examples": [
        "The first example is a filter that will remove all comments from an HTML file. This is achieved",
        "by simply overriding the comment method to do nothing.",
        "package CommentStripper;",
        "require HTML::Filter;",
        "@ISA=qw(HTML::Filter);",
        "sub comment { }  # ignore comments",
        "The second example shows a filter that will remove any <TABLE>s found in the HTML file. We",
        "specialize the start() and end() methods to count table tags and then make output not happen",
        "when inside a table.",
        "package TableStripper;",
        "require HTML::Filter;",
        "@ISA=qw(HTML::Filter);",
        "sub start",
        "my $self = shift;",
        "$self->{tableseen}++ if $[0] eq \"table\";",
        "$self->SUPER::start(@);",
        "sub end",
        "my $self = shift;",
        "$self->SUPER::end(@);",
        "$self->{tableseen}-- if $[0] eq \"table\";",
        "sub output",
        "my $self = shift;",
        "unless ($self->{tableseen}) {",
        "$self->SUPER::output(@);",
        "If you want to collect the parsed text internally you might want to do something like this:",
        "package FilterIntoString;",
        "require HTML::Filter;",
        "@ISA=qw(HTML::Filter);",
        "sub output { push(@{$[0]->{fhtml}}, $[1]) }",
        "sub filteredhtml { join(\"\", @{$[0]->{fhtml}}) }"
    ],
    "see_also": []
}