collapse collapse
* User Info
 
 
Welcome, Guest. Please login or register.
* Search

* Board Stats
  • stats Total Members: 989
  • stats Total Posts: 18366
  • stats Total Topics: 2501
  • stats Total Categories: 7
  • stats Total Boards: 35
  • stats Most Online: 1144

Author Topic: iconv  (Read 2879 times)

0 Members and 1 Guest are viewing this topic.

Offline Brianich

  • BeBot Rookie
  • *
  • Posts: 18
  • Karma: +0/-0
  • Kingpin Fixer
iconv
« on: December 04, 2006, 03:16:55 am »
Hello there, I am Trying to make bot friendly with Cyrillic encoding,

what do doing wrong?
1) putted php_iconv.dll to php.ini
2) changed bot.php with:
Quote
$msg=iconv($msg,"utf-8","cp1251");

But now, bot giving me empty messages.


Thanks

Using: Must die XP, php 5.1.5, Bebot 0.2.8
Super "Fixbrian" Girl
RK1, Clan
Current project: No data avaible...

Offline Khalem

  • BeBot Founder
  • Administrator
  • ********
  • Posts: 1169
  • Karma: +0/-0
    • http://www.ancarim.com
Re: iconv
« Reply #1 on: December 04, 2006, 04:55:55 pm »
It's a bit hard for me to test cyrillic support offhand, although if you can provide an example string i can try and see if i can make some headway.

Remember the by default the bot decodes everything from UTF-8 into ISO-8859-1 using utf8_decode.

Be sure to look for all instances of utf8_decode and utf8_encode in Bot.php and replace them with iconv
BeBot Founder and Fixer Kingpin

Offline Brianich

  • BeBot Rookie
  • *
  • Posts: 18
  • Karma: +0/-0
  • Kingpin Fixer
Re: iconv
« Reply #2 on: December 06, 2006, 06:35:16 pm »
I found another solution. don't need use iconv

adding to bot.php after <?
Quote
function utf2win1251 ($s)
{
 $out = "";

 for ($i=0; $i<strlen($s); $i++)
 {
  $c1 = substr ($s, $i, 1);
  $byte1 = ord ($c1);
  if ($byte1>>5 == 6) // 110x xxxx, 110 prefix for 2 bytes unicode
  {
   $i++;
   $c2 = substr ($s, $i, 1);
   $byte2 = ord ($c2);
   $byte1 &= 31; // remove the 3 bit two bytes prefix
   $byte2 &= 63; // remove the 2 bit trailing byte prefix
   $byte2 |= (($byte1 & 3) << 6); // last 2 bits of c1 become first 2 of c2
   $byte1 >>= 2; // c1 shifts 2 to the right

   $word = ($byte1<<8) + $byte2;
   if ($word==1025) $out .= chr(168);                    // ?
   elseif ($word==1105) $out .= chr(184);                // ?
   elseif ($word>=0x0410 && $word<=0x044F) $out .= chr($word-848); // ?-? ?-?
   else
   { 
     $a = dechex($byte1);
     $a = str_pad($a, 2, "0", STR_PAD_LEFT);
     $b = dechex($byte2);
     $b = str_pad($b, 2, "0", STR_PAD_LEFT);
     $out .= "&#x".$a.$b.";";
   }
  }
  else
  {
   $out .= $c1;
  }
 }

 return $out;
}

function cp1251_utf8( $sInput )
{
   $sOutput = "";

   for ( $i = 0; $i < strlen( $sInput ); $i++ )
   {
       $iAscii = ord( $sInput[$i] );

       if ( $iAscii >= 192 && $iAscii <= 255 )
           $sOutput .=  "&#".( 1040 + ( $iAscii - 192 ) ).";";
       else if ( $iAscii == 168 )
           $sOutput .= "&#".( 1025 ).";";
       else if ( $iAscii == 184 )
           $sOutput .= "&#".( 1105 ).";";
       else
           $sOutput .= $sInput[$i];
   }
   
   return $sOutput;
}
After replacing "utf8_encode" to "cp1251_utf8"
and "utf8_decode" to "utf2win1251"

After this, bot can understand Cyrillic.

Info by NStorm RK1
Super "Fixbrian" Girl
RK1, Clan
Current project: No data avaible...

 

* Recent Posts
Com bot module by bitnykk
[November 25, 2024, 05:36:11 pm ]


0.8.x updates for AO by bitnykk
[June 23, 2024, 03:19:47 pm ]


0.8.x updates for AoC by bitnykk
[June 23, 2024, 03:19:44 pm ]


[AoC] special char for items module by bitnykk
[February 09, 2024, 09:41:18 pm ]


BeBot still alive & kicking ! by bitnykk
[December 17, 2023, 12:58:44 am ]

* Who's Online
  • Dot Guests: 108
  • Dot Hidden: 0
  • Dot Users: 0

There aren't any users online.
* Forum Staff
bitnykk admin bitnykk
Administrator
Khalem admin Khalem
Administrator
WeZoN gmod WeZoN
Global Moderator
SimplePortal 2.3.7 © 2008-2024, SimplePortal