Why does a sort method not work correctly on LINUX servers? [closed]

4

I have a question, I have a function to sort a array that has names of people with accent (UTF-8). It works correctly on WINDOWS servers, but when I run the code to run LINUX servers, the accentation gets interrogated and does not order correctly what will it be? I've browsed all of order words with accents in PHP ", and everyone uses the method as I use it. I've tried usort uksort uasort none worked.

arrayMembros[$arrayDados2[0]] = array("idUsuario" => @$arrayDados2[0] , "nome" => ucwords(strtolower(utf8_encode(@$arrayDados2[1]))) , "sobrenome" => ucwords(strtolower(utf8_encode(@$arrayDados2[2])))    );

uasort(

    $arrayMembros,

     function( $a, $b ) {
        $variavela = iconv('UTF-8', 'ASCII//TRANSLIT', $a["nome"]);
        $variavelb = iconv('UTF-8', 'ASCII//TRANSLIT', $b["nome"]);

         return strcmp($variavela, $variavelb);
     }
);

Result on LINUX server:

  • ? nio Lima
  • Alana Siqueira
  • Fulana da Silva

Expected result (and also result on WINDOWS server):

  • Alana Siqueira
  • Ênio Lima
  • Fulana da Silva

Do not ask me to remove utf8_encode from the code, because I already did it and it does not, except that instead of pure interrogation, the result is the diamond query. The data comes from text files and I want to display them directly on the page without having to insert them into a database and gives a ORDER command for the data to come sorted.

Code:

$url = file_get_contents(verificar()."GERAL_getUsuariosGrupo.asp?idGrupo='$idGrupo'");

    $arrayDados = explode(";;",$url);
    $arrayMembros = array();
    $arrayMembros2 = array();

    foreach($arrayDados as $dados){
        $arrayDados2 = explode("|",$dados);
        $arrayMembros[$arrayDados2[0]] = array("idUsuario" => @$arrayDados2[0] , "nome" => ucwords(strtolower(@$arrayDados2[1])) , "sobrenome" => ucwords(strtolower(@$arrayDados2[2]))    );
        }


        usort(

    $arrayMembros,

     function( $a, $b ) {
        $variavela = iconv('UTF-8', 'ASCII//TRANSLIT', $a["nome"]);
        $variavelb = iconv('UTF-8', 'ASCII//TRANSLIT', $b["nome"]);

         return strcmp($variavela, $variavelb);
     }
);

Ps: I would like to thank you for this and I apologize for not being able to comment on the link I suggested above, because this stackoverflow policy of 50 reputation points to comment forced me to open another thread.

    
asked by anonymous 12.08.2015 / 22:29

1 answer

0

Are you running this code in the context of a Web page? It may be that the page is not in UTF-8, so strings may be being received in ISO-8859-1 format, which explains why "" "has been corrupted.

If it's Apache, try using

AddDefaultCharset UTF-8

in the configuration, and make sure the PHP page has the

<meta http-equiv="Content-Type" content="text/html; charset="UTF-8">
    
12.08.2015 / 22:42