Created
November 7, 2010 06:49
-
-
Save trung/665987 to your computer and use it in GitHub Desktop.
Convert Unicode to Decimal NCR
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use utf8; | |
# convert unicode to Decimal NCR format | |
sub convertUnicodeToDecimalNCR { | |
my ($self, $str) = @_; | |
# important | |
utf8::decode($str); | |
my $ret_str = ""; | |
while ($str =~ /(.)/g) { | |
my $c = $1; | |
my $b = ord($c); | |
if ($b > ord('z') && $b ne 123 && $b ne 125 && $b ne 126) { | |
$ret_str .= "&#".$b.";"; | |
} else { | |
$ret_str .= $c; | |
} | |
} | |
# $str =~ s/./"&#".ord($&).";" if /eg; | |
return $ret_str; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment