Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2013-01-26
7
Medium Priority
?
451 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 400 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 1600 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

618 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