douye8500 2016-10-10 00:31
浏览 61
已采纳

如何在PHP中从IMAP检索Unicode字符?

I'm trying to parse an email that is partially written in English and partially written in Japanese using PHP. Here's the code I have so far:

if ($mbox = imap_open($mailbox, $username, $password)) {

    $inbox = imap_check($mbox);
    $total = (int) $inbox->Nmsgs;
    $min = max(1, $total - 10);

    // fetch 10 most recent emails
    if ($total > 0 && ($emails = imap_fetch_overview($mbox, "{$min}:{$total}"))) {

        foreach ($emails as $email) {

            $body = imap_body($mbox, $email->uid, FT_UID);

            // for testing purposes
            echo $body;

            // parsing logic here

        }
    }
}

So as you can see I'm just echoing out the plaintext body of the email, just to test things, and here's part of the echoed response I get when I run this script:

Your Japanese word of the day is: ç”·ã®å­

However, the following is what I should see in place of that, based on what's actually in the email:

Your Japanese word of the day is: 男の子

So clearly something's being lost in translation (pun intended). I'm using some simple string manipulation to try and parse the Japanese characters, and then insert them into a MySQL database. However, it's currently inserting those gobbledygook characters instead. What am I missing?

Edit: I'm using PHP version 5.4.45

  • 写回答

1条回答 默认 最新

  • doushi9856 2016-10-12 16:53
    关注

    So I'm not really sure how to get this working in PHP 5. I decided to try upgrading my server to PHP 7 and suddenly all of the code just started working.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了