?
Solved

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

Posted on 2013-01-26
7
Medium Priority
?
436 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
Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

 

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

Independent Software Vendors: 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!

Question has a verified solution.

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

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
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…
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…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

800 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