0

I've already looked at this article. Problem is like that; when I'm sending a letter through exim4 and subject is with Cyrillic letters I've got something like this in maillog:

T="\320\235\320\260\321\201\321\202\321\200\320\276\320\271\320\272\320\270 PHP"

instead of something normal.

Is there any function that can decode that in Perl?


$var1="\320\235..... PHP" printf("$var1") prints \320\235....PHP this may help. file logfile :ASCII text

solved at https://stackoverflow.com/questions/6031255

MealstroM
  • 1,517
  • 1
  • 17
  • 32

2 Answers2

0

print seems to get the job done:

$ perl -e 'print "\320\235\320\260\321\201\321\202\321\200\320\276\320\271\320\272\320\270 PHP" . "\n"'
Настройки PHP

No need to go to perl though:

$ printf "\320\235\320\260\321\201\321\202\321\200\320\276\320\271\320\272\320\270 PHP\n"
Настройки PHP
Eduardo Ivanec
  • 14,881
  • 1
  • 37
  • 43
  • ive got this line in variable and want to store it in database. $var1="\320\235....." if i insert this in db in that way ill get that \320\235 in my db. i dont want that. just this 'Настройки PHP' :) $vat1=printf($vat1).. – MealstroM May 17 '11 at 12:03
  • Mmm, try this: `$utfvar1 = utf8::upgrade($var1)`, and use utfvar1 afterwards. From perldoc utf8: "Converts in-place the internal representation of the string from an octet sequence in the native encoding (Latin-1 or EBCDIC) to UTF-X.". – Eduardo Ivanec May 17 '11 at 12:09
  • that didnt helped. it just returned numbers 70 or 4 – MealstroM May 17 '11 at 12:15
  • I misread the docs, sorry. It modifies the string in-place and returns a number (http://perldoc.perl.org/utf8.html), you should keep using `$var1` afterwards. I'm assuming your database uses utf-8 - is that right? – Eduardo Ivanec May 17 '11 at 12:21
  • Yes. it uses utf8. and using var1 after didnt help either. – MealstroM May 17 '11 at 12:33
0
use Encode::Escape;
$var1='\321\213';
         print decode 'unicode-escape', $var1;
#correct mysql view in phpmyadmin
$dbh = DBI->connect('DBI:mysql:database=test', 'testuser', 'testpass', { mysql_enable_utf8 => 1});

Dont know why, but that works

MealstroM
  • 1,517
  • 1
  • 17
  • 32