skazat has asked for the wisdom of the Perl Monks concerning the following question:

i'm using the HTML::Entities module to parse some characters for our content management system, although now I've shot myself in the foot, since we allow html to be inputed into the forms, HTML::Entities likes to take these characters - >,<,", ' and & that have special meaning and convert them to their entities, which is what it's supposed to do but I want it to do everything but those.

The docs do point out that you can pass a list of unsafe characters to the script, but I kinda want the opposite, I want to pass the safe characters to the script, since the list is much smaller ;)

Can anyone help me with how to pass all the unsafe characters i want parsed execpt the ones above? it would seem that this is a probelm someone else has come across,

cheers

-justin simoni
!skazat!

Replies are listed 'Best First'.
Re: HTML::Entities question
by tachyon (Chancellor) on Oct 27, 2001 at 23:58 UTC

    A little hard to understand what you are doing but if you just want to get all the ASCII chars not in a short list you would just:

    my @unsafe = qw ( < > " ' ); my %unsafe; @unsafe{@unsafe} = @unsafe; # make a hash lookup table for (1..255) { push @safe, chr($_) unless defined $unsafe{ chr($_) }; } print @safe;
    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

      i pretty much want to parse out characters that have html entities except my little list of ',",<,> and &

      and HTML::Entities allows you to parse out characters that have entities, and also allow you to state exactly which ones you want parsed. I want to state which ones i don't want parsed. Seeing there isn't any way to do this, I want a workaround (dang nabiit!)

      I'll try what you gots,

       

      -justin simoni
      !skazat!

        ok, duh the example in the docs:

        encode_entities($a, "\200-\377");
        seems to do what i want nicely

         

        -justin simoni
        !skazat!