imap getting message body

Good afternoon. There is a function that pulls letters using imap by pop3

function get_body($box = false, $num){  
        if($num > $this->get_count())
            return null;
        if(!$box)
            $box = $this->box;
        $struct = imap_fetchstructure($box,$num);
        if(!empty($struct->parts)){
            for($i = 0, $j = count($struct->parts); $i < $j; $i++){
                $part = $struct->parts[$i];
                if($part->subtype == 'PLAIN'){
                    $body = imap_fetchbody($box,$num, $i+1);
                }
            }
        }
        else
            $body = imap_body($box,$num);
        return $body;
    }

How do I convert the message body to utf8?


Answer 1, authority 100%

Here are the PHP functions for working with utf-8 using the XML extension:

utf8_encode(string); 
utf8_decode(utf8_string);

and there is also a function for transcoding strings of other encodings:

iconv('__','__','___');

for example:

$win1251_str=iconv('KOI8-R','WINDOWS-1251',$koi8string);