note 52623 added to function.imap-sort

From: Date: Sat, 07 May 2005 10:17:37 +0000
Subject: note 52623 added to function.imap-sort
Groups: php.notes 
Request: Send a blank email to php-notes+get-89069@lists.php.net to get a copy of this message
imap_sort uses the c-client library to sort messages. This library currently does not support locale-based sort for foreign languages (Although it has charset option). They are working on this(http://www.washington.edu/imap/IMAP-FAQs/#1.12), but you can use the following function which uses strcoll() for locale-based sorting. Pease note that this is required for SUBJECT field sorting, because most of other fields are sorted correctly by imap_sort in any locale: 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"]=MIME::decode($val->subject, NLS::getCharset()); $k++; } usort ($unsorted, create_function('$a,$b','setlocale(LC_ALL,$locale);return strcoll($a["subject"],$b["subject"]);')); for ($m=0;$m<count($unsorted);$m++) array_push($sortresult,$unsorted[$m]["uid"]); if ($reverse) $sortresult = array_reverse($sortresult); return $sortresult; } Usage example: $sorted = imap_locale_sort($stream,SORTSUBJECT,0,'fa_IR',0); ---- Manual Page -- http://www.php.net/manual/en/function.imap-sort.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+52623 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+52623&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+52623&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+52623&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+52623&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+52623&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+52623&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#89069) next »