nix, shell, perl, php, mysql and mac os x tips and tricks

Friday, November 3, 2017

search and replace unicode characters for ASCII output in perl

I don't know why you would EVER need this :P but just in case, this handles most of the open/close quote and double quote issues that arise when you need to output to ASCII
 $string =~ s/[\x{00E2}|\x{00C3}|\x{00C2}]?[\x{0080}|\x{0082}|\x{0083}|\x{0000}]?[\x{0099}|\x{00BA}|\x{00B9}|\x{0098}]/'/ig;
 $string =~ s/[\x{00E2}|\x{00C3}|\x{00C2}]?[\x{0080}|\x{0082}|\x{0083}|\x{0000}]?[\x{009C}|\x{009D}|\x{0093}|\x{0094}]/"/ig;
 $string =~ s/\x{2018}/'/ig;
 $string =~ s/\x{201A}/'/ig;
 $string =~ s/\x{2019}/'/ig;
 $string =~ s/\x{2039}/'/ig;
 $string =~ s/\x{203A}/'/ig; 
 $string =~ s/\x{0092}/'/ig; 
 $string =~ s/\x{0093}/"/ig;
 $string =~ s/\x{0094}/"/ig;
 $string =~ s/\x{201C}/"/ig;
 $string =~ s/\x{201D}/"/ig;
 $string =~ s/\x{201E}/"/ig;