php-i18n Digest 2 Jun 2005 01:54:07 -0000 Issue 287
Topics (messages 864 through 866):
Re: imap sort localization in subject field
864 by: persian-horde.metanetworking.com
865 by: persian-horde.metanetworking.com
Re: simple katakana to romaji converter function
866 by: Lapo Luchini
Administrivia:
To subscribe to the digest, e-mail:
[EMAIL PROTECTED]
To unsubscribe from the digest, e-mail:
[EMAIL PROTECTED]
To post to the list, e-mail:
[email protected]
----------------------------------------------------------------------
--- Begin Message ---
Hello,
We used MIME and NLS libraries in our previous code 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<count($unsorted);$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",'salman',"123");
if ($mbox)
echo ("Connection Successful!");
$sorted = imap_locale_sort($mbox,SORTSUBJECT,0,'fa_IR',0);
print_r($sorted);
print ("\n\n");
$sorted = imap_sort($mbox,SORTSUBJECT,SE_UID);
print_r($sorted);
imap_close($mbox);
<[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Hello all,
>
> 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:
>
--- End Message ---
--- Begin Message ---
Hello,
We used MIME and NLS libraries in our previous code 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<count($unsorted);$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","usrname","password");
if ($mbox)
echo ("Connection Successful!");
$sorted = imap_locale_sort($mbox,SORTSUBJECT,0,'fa_IR',0);
print_r($sorted);
print ("\n\n");
$sorted = imap_sort($mbox,SORTSUBJECT,SE_UID);
print_r($sorted);
imap_close($mbox);
<[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Hello all,
>
> 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:
>
Thanks
persian-horde team
--- End Message ---
--- Begin Message ---
Gary Ross wrote:
> I'm looking for a simple function to convert katakana to romaji in php.
> I don't want to use kakasi but pure php. It should be easy enough to
> write myself but if there is something already out there...
I solved the problem this way (I know, separating the string and using a
big "switch/case" on each char *may* be faster, as this tries to match
each character many times (one for each search string, I guess), but
this way is *WAY* more readable):
$k2r = array('/きゃ/' => 'kya', '/きゅ/' => 'kyu', '/きょ/' => 'kyo', '/
しゃ/' => 'sha', '/しゅ/' => 'shu', '/しょ/' => 'sho', '/ちゃ/' =>
'cha', '/ちゅ/' => 'chu', '/ちょ/' => 'cho', '/にゃ/' => 'nya', '/にゅ/'
=> 'nyu', '/にょ/' => 'nyo', '/ひゃ/' => 'hya', '/ひゅ/' => 'hyu', '/
ひょ/' => 'hyo', '/みゃ/' => 'mya', '/みゅ/' => 'myu', '/みょ/' =>
'myo', '/りゃ/' => 'rya', '/りゅ/' => 'ryu', '/りょ/' => 'ryo', '/ぎゃ/'
=> 'gya', '/ぎゅ/' => 'gyu', '/ぎょ/' => 'gyo', '/じゃ/' => 'ja', '/じゅ
/' => 'ju', '/じょ/' => 'jo', '/ぢゃ/' => 'ja', '/ぢゅ/' => 'ju', '/ぢょ
/' => 'jo', '/びゃ/' => 'bya', '/びゅ/' => 'byu', '/びょ/' => 'byo', '/
ぴゃ/' => 'pya', '/ぴゅ/' => 'pyu', '/ぴょ/' => 'pyo', '/あ/' => 'a', '/
い/' => 'i', '/う/' => 'u', '/え/' => 'e', '/お/' => 'o', '/か/' =>
'ka', '/き/' => 'ki', '/く/' => 'ku', '/け/' => 'ke', '/こ/' => 'ko', '/
さ/' => 'sa', '/し/' => 'shi', '/す/' => 'su', '/せ/' => 'se', '/そ/' =>
'so', '/た/' => 'ta', '/ち/' => 'chi', '/つ/' => 'tsu', '/て/' => 'te',
'/と/' => 'to', '/な/' => 'na', '/に/' => 'ni', '/ぬ/' => 'nu', '/ね/'
=> 'ne', '/の/' => 'no', '/は/' => 'ha', '/ひ/' => 'hi', '/ふ/' => 'fu',
'/へ/' => 'he', '/ほ/' => 'ho', '/ま/' => 'ma', '/み/' => 'mi', '/む/'
=> 'mu', '/め/' => 'me', '/も/' => 'mo', '/や/' => 'ya', '/ゆ/' => 'yu',
'/よ/' => 'yo', '/ら/' => 'ra', '/り/' => 'ri', '/る/' => 'ru', '/れ/'
=> 're', '/ろ/' => 'ro', '/わ/' => 'wa', '/ゐ/' => 'wi', '/ゑ/' => 'we',
'/を/' => 'wo', '/ん/' => 'n', '/が/' => 'ga', '/ぎ/' => 'gi', '/ぐ/' =>
'gu', '/げ/' => 'ge', '/ご/' => 'go', '/ざ/' => 'za', '/じ/' => 'ji', '/
ず/' => 'zu', '/ぜ/' => 'ze', '/ぞ/' => 'zo', '/だ/' => 'da', '/ぢ/' =>
'ji', '/づ/' => 'zu', '/で/' => 'de', '/ど/' => 'do', '/ば/' => 'ba', '/
び/' => 'bi', '/ぶ/' => 'bu', '/べ/' => 'be', '/ぼ/' => 'bo', '/ぱ/' =>
'pa', '/ぴ/' => 'pi', '/ぷ/' => 'pu', '/ぺ/' => 'pe', '/ぽ/' => 'po',
'/aa/' => 'ā', '/e[ei]/' => 'ē', '/ii/' => 'ī', '/o[ou]/' => 'ō', '/uu/'
=> 'ū');
function romaji($hiragana) {
global $k2r;
return preg_replace(array_keys($k2r), array_values($k2r), $kana);
}
--
L a p o L u c h i n i
l a p o @ l a p o . i t
w w w . l a p o . i t /
--- End Message ---