waplet Posted February 10, 2011 Report Share Posted February 10, 2011 $string = "glāžšķūņa rūķīš"; mb_internal_encoding("UTF-8"); var_dump(setlocale(LC_COLLATE,"Latvian_Latvia.1257")); sort($letters, SORT_LOCALE_STRING); a, š, ī, ū, ķ, ņ, ā, ž, g, l, r, izvada šādi. OS: Win 7 Ultimate 32 bit Regional un pāŗejais: Latvian Latvia un tml.. Ko darīt, lai pareizi kārto? Quote Link to comment Share on other sites More sharing options...
waplet Posted February 10, 2011 Author Report Share Posted February 10, 2011 Katram gadījumam, vai ir kāds īsāks pierakst , kā šis? function latvian_ord($char) { static $alf_flip=array('1'=>-9,'2'=>-8,'3'=>-7,'4'=>-6,'5'=>-5,'6'=>-4,'7'=>-3,'8'=>-2,'9'=>-1,'a'=>0, 'ā'=>1, 'b'=>2, 'c'=>3, 'č'=>4, 'd'=>5, 'e'=>6, 'ē'=>7, 'f'=>8, 'g'=>9, 'ģ'=>10, 'h'=>11, 'i'=>12, 'ī'=>13, 'j'=>14, 'k'=>15, 'ķ'=>16, 'l'=>17, 'ļ'=>18, 'm'=>19, 'n'=>20, 'ņ'=>21, 'o'=>22, 'p'=>23, 'r'=>24, 's'=>25, 'š'=>26, 't'=>27, 'u'=>28, 'ū'=>29, 'v'=>30, 'z'=>31, 'ž'=>32); if (isset($alf_flip[$char])) return $alf_flip[$char]; else return -10; } function compare_strings_lv($str1,$str2) { $len=max(mb_strlen($str1),mb_strlen($str2)); if ($str1==$str2) return 0; for ($i=0;$i<$len;$i++) { if ((mb_substr($str1,$i,1))=='') return -1; if ((mb_substr($str2,$i,1))=='') return 1; $str1=mb_strtolower($str1); $str2=mb_strtolower($str2); if (latvian_ord(mb_substr($str1,$i,1))>latvian_ord(mb_substr($str2,$i,1))) { return 1; } else if (latvian_ord(mb_substr($str1,$i,1))<latvian_ord(mb_substr($str2,$i,1))) return -1; } } usort($letters, 'compare_strings_lv'); Quote Link to comment Share on other sites More sharing options...
mounkuls Posted February 10, 2011 Report Share Posted February 10, 2011 (edited) Hmm...ja sapratu kur tā vaina, skaties noderīgajās funkcijās. Man lieka, ka tur bija funkcijas utf2win un win2utf mūsmāju kadriem. EDIT: vispār ne to sapratu, sortēt ir pavisam cits kas. Īstenībā šaubos vai tāda funkcija ir, būs vien pašam jāštuko. Masīvs ar alfabētu, teksta čarus sapin ar indeksiem, sazortē un samauc apakaļ citā masīvā jau sakārtotu. Nu tā kautkā. Edited February 10, 2011 by mounkuls Quote Link to comment Share on other sites More sharing options...
novi4ok123 Posted September 30, 2013 Report Share Posted September 30, 2013 @wapletmmm, bet ka but ar to, ja vajag sakartot neviss string bet array? Quote Link to comment Share on other sites More sharing options...
marrtins Posted September 30, 2013 Report Share Posted September 30, 2013 Tad raksti mapperi un neaizmirsti vēl kādus personas kodus. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.