Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Eventually this problem cannot be solved in a simple way without using recoded strings (UTF-8 → Windows-1252 or ISO-8859-1) as suggested by ΤΖΩΤΖΙΟΥ due to an obvious PHP bug as discovered by Huppie. To summarize the problem, I created the following code snippet which clearly demonstrates that the problem is the strcoll() function when using the 65001 Windows-UTF-8-codepage.</p> <pre><code>function traceStrColl($a, $b) { $outValue=strcoll($a, $b); echo "$a $b $outValue\r\n"; return $outValue; } $locale=(defined('PHP_OS') &amp;&amp; stristr(PHP_OS, 'win')) ? 'German_Germany.65001' : 'de_DE.utf8'; $string="ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÜabcdefghijklmnopqrstuvwxyzäöüß"; $array=array(); for ($i=0; $i&lt;mb_strlen($string, 'UTF-8'); $i++) { $array[]=mb_substr($string, $i, 1, 'UTF-8'); } $oldLocale=setlocale(LC_COLLATE, "0"); var_dump(setlocale(LC_COLLATE, $locale)); usort($array, 'traceStrColl'); setlocale(LC_COLLATE, $oldLocale); var_dump($array); </code></pre> <p>The result is:</p> <pre><code>string(20) "German_Germany.65001" a B 2147483647 [...] array(59) { [0]=&gt; string(1) "c" [1]=&gt; string(1) "B" [2]=&gt; string(1) "s" [3]=&gt; string(1) "C" [4]=&gt; string(1) "k" [5]=&gt; string(1) "D" [6]=&gt; string(2) "ä" [7]=&gt; string(1) "E" [8]=&gt; string(1) "g" [...] </code></pre> <p>The same snippet works on a Linux machine without any problems producing the following output:</p> <pre><code>string(10) "de_DE.utf8" a B -1 [...] array(59) { [0]=&gt; string(1) "a" [1]=&gt; string(1) "A" [2]=&gt; string(2) "ä" [3]=&gt; string(2) "Ä" [4]=&gt; string(1) "b" [5]=&gt; string(1) "B" [6]=&gt; string(1) "c" [7]=&gt; string(1) "C" [...] </code></pre> <p>The snippet also works when using Windows-1252 (ISO-8859-1) encoded strings (of course the mb_* encodings and the locale must be changed then).</p> <p>I filed a bug report on <a href="http://bugs.php.net" rel="noreferrer">bugs.php.net</a>: <a href="http://bugs.php.net/bug.php?id=46165" rel="noreferrer">Bug #46165 strcoll() does not work with UTF-8 strings on Windows</a>. If you experience the same problem, you can give your feedback to the PHP team on the bug-report page (two other, probably related, bugs have been classified as <em>bogus</em> - I don't think that this bug is <em>bogus</em> ;-).</p> <p>Thanks to all of you.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload