Solved

function.mb-decode-mimeheader is not working for this output

Posted on 2013-01-26
7
416 Views
Last Modified: 2013-01-30
please see related question:

http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_28007323.html


manual: http://php.net/manual/en/function.mb-decode-mimeheader.php

echo mb_decode_mimeheader('=?iso-8859-1?B?RGlhbmEgQ3Jpc3TzYmFs?=');

output
Diana Cristóbal


but this input is not producing the correct output:


input:
=?KOI8-R?B?6dLJzsEg78zaz8XXwQ==?=

output:
??????????
want this output:
¿¿¿¿¿ ¿¿¿¿¿¿¿
even experts exchange will not show it when I copy paste

so I attach image

not showing in a browser
0
Comment
Question by:rgb192
  • 3
  • 2
  • 2
7 Comments
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 38824035
Try this:
<?php
error_reporting(E_ALL);

mb_internal_encoding('UTF-8');

checkString('=?iso-8859-1?B?RGlhbmEgQ3Jpc3TzYmFs?=');
checkString('=?KOI8-R?B?6dLJzsEg78zaz8XXwQ==?=');

function checkString($s) {
	echo 'input: '.$s.'<br>';
	$s = mb_decode_mimeheader($s);
	echo 'output: '.charset_decode_utf_8($s).'<br><br>';
}

// this from: http://php.net/manual/en/function.utf8-decode.php
function charset_decode_utf_8 ($string) {
      /* Only do the slow convert if there are 8-bit characters */
    /* avoid using 0xA0 (\240) in ereg ranges. RH73 does not like that */
    if (! ereg("[\200-\237]", $string) and ! ereg("[\241-\377]", $string))
        return $string;

    // decode three byte unicode characters
    $string = preg_replace("/([\340-\357])([\200-\277])([\200-\277])/e", "'&#'.((ord('\\1')-224)*4096 + (ord('\\2')-128)*64 + (ord('\\3')-128)).';'", $string);

    // decode two byte unicode characters
    $string = preg_replace("/([\300-\337])([\200-\277])/e", "'&#'.((ord('\\1')-192)*64+(ord('\\2')-128)).';'", $string);

    return $string;
}

?>

Open in new window

0
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 38824039
That decode function was in the comments in the manual of utf8_decode, apparently taken from the sources of SquirrelMail. Nice!

Important also is setting that internal encoding, could also be done in php.ini I guess.

EDIT: some more info, I tried 'everything' related to doctype, meta tags, php header setting of charset (needed according to a lot of other solutions), physical file type (needed for literals in the page) etc but took it all out and it still works, no meta, no charset header, showing cyrillic text. Just the internal encoding seems important, as well as the alternative way to handle htmlentities.
0
 
LVL 11

Expert Comment

by:mcnute
ID: 38824134
I've tried a couple of things, maybe with your local server encoding in php.ini it works:

iconv_mime_decode('=?KOI8-R?B?6dLJzsEg78zaz8XXwQ==?=', 0, 'koi8-r');

Open in new window


$new = mb_convert_encoding($str, 'windows-1251', 'KOI8-R');

Open in new window

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:rgb192
ID: 38833439
>>robert_schutt
output good



>>I've tried a couple of things, maybe with your local server encoding in php.ini it works:

I dont understand how to make your code work
0
 
LVL 11

Assisted Solution

by:mcnute
mcnute earned 100 total points
ID: 38834779
Well, in my scripts I can't get the cyrillic to print out well. Whereas this guy is capable of transcoding it into cyrillic:

http://2cyr.com/decode/

Maybe he can help you with your problem.
0
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 400 total points
ID: 38835137
output good
Do you mean the output on my link? Or the code works for you? If the latter, then we're done? ;-)
0
 

Author Closing Comment

by:rgb192
ID: 38836345
thanks

I waited to see if mcnute could create php code, but provided an web link of a converter,

but robert_schutt provided the best answer because of php code in my php zone question
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now