ive already looked at this article. Problem is like that, when im sending a letter throug exim4 and subject is with cyrrilic letters ive 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 from 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 http://stackoverflow.com/questions/6031255

link|improve this question

feedback

2 Answers

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
link|improve this answer
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 (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
feedback
up vote 0 down vote accepted
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

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.