【问题标题】:PHP - ASCII special characters (without MySQL)PHP - ASCII 特殊字符(没有 MySQL)
【发布时间】:2012-04-11 09:46:47
【问题描述】:

我正在做这个 PHP 页面,它可以访问一个 Google 帐户,而不是显示所有电子邮件。我也定义了一个 header = UTF-8 和 meta,我使用了很多 PHP 函数将输出转换为 UTF,但我不断得到奇怪的图标而不是 ASCII 特殊字符。如çéã

    header("Content-Type: text/html; charset: UTF-8");
    $message = imap_fetchbody($inbox,$email_number,2);
    echo $message;

应该是什么输出:

çççç

我得到了什么:

=E7=E7=E7=E7

【问题讨论】:

    标签: php character-encoding


    【解决方案1】:

    使用imap_qprint(请参阅该页面上的第一条评论以获取替代解决方案)。

    【讨论】:

    • 我使用了第一个评论的解决方案,成功了,非常感谢。
    【解决方案2】:

    这似乎是一个已知问题,关于imap_fetchbody PHP doc page 的第一条评论。

    使用imap_qprint 或使用评论解决方案:

    <?php
    function ReplaceImap($txt) {
      $carimap = array("=C3=A9", "=C3=A8", "=C3=AA", "=C3=AB", "=C3=A7", "=C3=A0", "=20", "=C3=80", "=C3=89");
      $carhtml = array("é", "è", "ê", "ë", "ç", "à", "&nbsp;", "À", "É");
      $txt = str_replace($carimap, $carhtml, $txt);
    
      return $txt;
    }
    
    $mbox = imap_open("{imap.gmail.com:993/imap/ssl}INBOX", "login", "pass");
    $no = 5; // Mail to show (mail number)
    
    $text = imap_fetchbody($mbox, $no, 1);
    $text = imap_utf8($text);
    $text = ReplaceImap($text);
    $text = nl2br($text);
    
    echo $text;
    ?>
    

    【讨论】:

    • 通过阅读下面的评论,我使用了这个: $message = preg_replace("/\=([A-F][A-F0-9])/","%$1",$message); $message = urldecode($message); $message = utf8_encode($message);
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-11-29
    • 1970-01-01
    • 2010-10-12
    • 1970-01-01
    • 1970-01-01
    • 2015-03-08
    • 1970-01-01
    相关资源
    最近更新 更多