[Date Prev][Date Next]
[Chronological]
[Thread]
[Top]
Re: Fwd: Re: Special characters in attribute values
On Wed, Nov 21, 2001 at 03:17:42PM +0100, Alejandra Moreno wrote:
> >Date: Wed, 21 Nov 2001 11:01:46 +0100
> >To: Stig Venaas <Stig@OpenLDAP.org>
> >From: Alejandra Moreno <alejandra.moreno@atrete.ch>
> >Subject: Re: Special characters in attribute values
> >
> >Something isn't working on the utf2ANSI because if I encode it and decode
> >it I don't get the same string. Do you know what's wrong? Here are both
> >scripts. Thnaks.
> >
> ># ======================================================================
> >sub ansi2UTF($){
> >my $string = shift;
> >my @chars = split(//, $string);
> >my $lowByte;
> >my $highByte;
> >my $i;
> >for ($i=0;$i<=$#chars;$i++){
> >my $assciCode = ord($chars[$i]);
> >if ($assciCode > 127){
> >$lowByte = $assciCode & 192;
> >$lowByte = $lowByte >> 6;
> >$lowByte = $lowByte & 3;
> >$lowByte += 192;
> >$highByte = $assciCode & 63;
> >$highByte += 128;
I think this should be:
$lowByte = $assciCode & 192;
$lowByte = $lowByte >> 6;
$highByte = $assciCode & 63;
$highByte += 128;
> ># ======================================================================
> >sub utf2ANSI($){
Didn't study this code that much, but if you know that your characters
have values 0-255, the following should suffice I think:
function utf8_iso8859($s)
{
$t = "";
$n = strlen($s);
for ($i=0; $i<$n; $i++) {
$c = ord($s[$i]);
if ($c>127 && $c<224) {
$t .= chr(($c&3)*64 | ord($s[++$i])&63);
} else {
$t .= $s[$i];
}
}
return $t;
}
Note that this is PHP code, but should be easy enough to understand.
Stig