[SP-pm] Função que verifica dados HTML

Luis Motta Campos luismottacampos at yahoo.co.uk
Thu Jan 14 05:10:24 PST 2010


Fernando wrote:
> Amigos, a função “strip_tags()” na linguagem PHP, previne entrada
> maliciosa de tags HTML. Qual seria a equivalente função aplicada à
> PERL?

Para remover tags (se você está preocupado com ataques, isso é o melhor
que você pode fazer), tente ler estes artigos:

"How to remove HTML tags from string", PerlMonks.org
http://www.perlmonks.org/?node=How%20do%20I%20remove%20HTML%20from%20a%20string%3F

"Simplify HTML Programatically", PerlMonks.org
http://www.perlmonks.org/?node_id=554145

  *  *  *

O Módulo HTML::Parse pode ajudar também:
http://search.cpan.org/~gaas/HTML-Parser-3.64/Parser.pm

use HTML::Parser;
  HTML::Parser->new(default_h => [sub { print shift }, 'text'],
                    comment_h => [""],
                   )->parse_file(shift || die) || die $!;

  *  *  *

Finalmente, tem o HTML::Scrubber:
http://search.cpan.org/~podmaster/HTML-Scrubber-0.08/Scrubber.pm

use HTML::Scrubber;
my $scrubber = HTML::Scrubber->new( allow => [ qw[ p b i u hr br ] ] );
print $scrubber->scrub($html);

  *  *  *

Espero que isso resolva o seu problema.

Putamplexos.
-- 
Luis Motta Campos is a software engineer,
Perl Programmer, foodie and photographer.


More information about the SaoPaulo-pm mailing list