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.

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

报告相同问题?

悬赏问题

  • ¥15 WPF 大屏看板表格背景图片设置
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示