php imap 邮件 排序,PHP imap_sort 用法 手册 | 示例代码

这段代码展示了如何使用纯PHP实现邮件按特定语言(如'fa_IR')的本地化排序功能。它首先获取邮件概述,然后使用自定义的排序函数`create_function`结合`strcoll`进行字符串比较。最后,返回根据主题排序的邮件UID列表。示例中,还对比了使用`imap_sort`原生函数的排序结果。

Hello,

We used MIME and NLS libraries in our previous code(imap_locale_sort) that

are part of PEAR and Horde projects, and so our function

was so specific. Here is the general (pure php) code for this

function:

function imap_locale_sort($stream,$criteria,$reverse,$locale,$options)

{

if ($criteria!=SORTSUBJECT)

return (imap_sort($stream,$criteria,$reverse,$options));

$unsorted = array();

$sortresult = array();

$MC=imap_check($stream);

$MN=$MC->Nmsgs;

$overview = imap_fetch_overview($stream,"1:$MN",0);

$k=0;

while( list($key,$val) = each($overview))

{

$unsorted[$k]["uid"]=$val->uid;

$unsorted[$k]["subject"]=imap_utf8($val->subject);

$k++;

}

usort ($unsorted, create_function('$a,$b','setlocale(LC_ALL,$locale);return strcoll($a["subject"],$b["subject"]);'));

for ($m=0;$m

array_push($sortresult,$unsorted[$m]["uid"]);

if ($reverse)

$sortresult = array_reverse($sortresult);

return $sortresult;

}

Sample usage:

$mbox = imap_open("{localhost:143}INBOX.sent-mail","userid","password");

if ($mbox)

echo ("Connection Successful!");

$sorted = imap_locale_sort($mbox,SORTSUBJECT,0,'fa_IR',0);

print_r($sorted);

print ("nn");

$sorted = imap_sort($mbox,SORTSUBJECT,SE_UID);

print_r($sorted);

imap_close($mbox);

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值