Solved

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

Posted on 2013-01-26
7
413 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:rgb192
Comment Utility
>>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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

763 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

14 Experts available now in Live!

Get 1:1 Help Now