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 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀