我正在使用IMAP从Gmail获取邮件。它工作正常,但当我查看邮件标题时,它的文本带有奇怪的符号。我已经尝试用Imap_qprint来证实它,但这并不适用于所有符号。
<?php
// Connecting to IMAP
$mailboxPath = "{imap.gmail.com:993/imap/ssl}INBOX";
$username = "mailadress";
$password = "password";
$mailStream = imap_open($mailboxPath, $username, $password) or die("can't connect: " . imap_last_error());
// Number of mails
$mails = imap_num_msg($mailStream);
// Cycle trough mails
for($i=1; $i<=$mails; $i++) {
// Get headerinfo mail
$headerinfo = imap_headerinfo($mailStream, $i);
// echo "<pre>";
// print_r($headerinfo);
// echo "</pre>";
// Select subject out headerinfo
$subject = $headerinfo->subject;
$subject = quoted_printable_decode($subject);
echo $subject . "<br>";
}
给我这样的科目:
=?UTF-8?Q?New_from_Codecademy:_Introdu?= =?UTF-8?Q?ction_to_Data_Analysis_ = F0 = 9F = 94 = 8D_ = F0 = 9F = 93 = 88?=
什么时候使用quoted_printable_decode()函数它已经清理了一点但仍未完成。它的外观如下:
=?UTF-8?Q?New_from_Codecademy:_Introdu?= =?UTF-8?Q?ction_to_Data_Analysis __?
如何将其转换为:
Codecademy的新内容:数据分析简介