Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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.

In reply to Re: zapping gremlins by imp
in thread zapping gremlins by jck

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and God said, "Let Newton be!"...

    How do I use this? | Other CB clients
    Other Users?
    Others making s'mores by the fire in the courtyard of the Monastery: (3)
    As of 2017-10-21 02:14 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      My fridge is mostly full of:

















      Results (269 votes). Check out past polls.

      Notices?