Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: zapping gremlins

by imp (Priest)
on Jul 02, 2006 at 04:55 UTC ( #558830=note: print w/replies, xml ) Need Help??


in reply to zapping gremlins

I suspect that the data is coming from MS Word, which loves to use custom quote and dash symbols.

If you copy the character and run something like this:

perl -e 'print ord(shift) . "\n"' ""

You should get 226.
But if you iterate over the list of characters sent in the actual form data it will be something different. (decimal 146, hex 92)

You could match this with \x92

$in{'content'} =~ s/\x92/’/g;
I do the following for msword character stripping:
# Somewhere in an init function I define the hex value => string mappi +ng # I find it easier to edit this way my %seed = ( '82' => ',', '83' => '<em>f</em>', '84' => ',,', '85' => '...', '88' => '^', '89' => ' /', '8B' => '<', '8C' => 'Oe', '91' => '`', '92' => '\'', '93' => '"', '94' => '"', '95' => '*', '96' => '-', '97' => '--', '98' => '<sup>~</sup>', '99' => '<sup>TM</sup>', '9B' => '>', '9C' => 'oe', ); # Build a mapping of the hex code to string lookup table. # I find it to be less error prone than maintaining it manually my %msword_replace = (); while (my ($hex, $replace_with) = each %seed) { $msword_replace{chr(hex($hex))} = $replace_with; } # Define a list of hex codes that will be used as the search patte +rn # Then create a regex with alternation for these codes my @hex_codes = map {'\x' . $_} keys %seed; $msword_re = sprintf "(%s)", join('|', @hex_codes); # And then later when I need to do the replacing: $data =~ s/$msword_re/$msword_replace{$1}/g;
There is probably a commonly used module for doing this, but hope this example helps.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://558830]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2021-11-30 18:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?