Solved

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

Posted on 2013-01-26
7
422 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
jQuery Toggle & Anchor Links 5 43
PHP and MSSQL Arrays and Variables 3 23
AJAX, If No returns don't let the AJAX Call run again 2 20
issue with DB import 1 17
These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses four methods for overlaying images in a container on a web page
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 look for a specific file type in a local or remote server directory using PHP.

839 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