php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #18096 sorting using usort() does not work
Submitted: 2002-07-01 15:20 UTC Modified: 2002-07-01 15:22 UTC
From: andre dot lourenco at link dot pt Assigned:
Status: Closed Package: Arrays related
PHP Version: 4.2.1 OS: OSF1 V4.0 1091
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: andre dot lourenco at link dot pt
New email:
PHP Version: OS:

 

 [2002-07-01 15:20 UTC] andre dot lourenco at link dot pt
This code works on a PHP Version 4.1.0 with 
Linux dorado 2.2.16-22smp #1 SMP Tue Aug 22 16:39:21 EDT 2000 i686 unknown

SYSTEM
Apache/1.3.24 (Unix) PHP/4.2.1 


BEGIN -- index.html --

<html lang="pt">
<head>
<title>118 TEL</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" background="imagens/fund
o.gif">
<select>
<?
    if (!isset($pais) || $pais == '-')
        echo "<option value=\"-\" selected>- escolha o pa?s -</option>\n";

    define ("S_ACENTOS", "????????????????????????????????????????????????????????????????");
    define ("S_NORMAIS", "AAAAAAACEEEEIIII NOOOOOOOUUUUY  aaaaaaaceeeeiiii nooooooouuuuy  ");

    function cmp($a, $b) {
        if ($a[1] == $b[1]) {
            $s1 = strtr($a[2], S_ACENTOS, S_NORMAIS);
            $s2 = strtr($b[2], S_ACENTOS, S_NORMAIS);
        } else {
            $s1 = strtr($a[1], S_ACENTOS, S_NORMAIS);
            $s2 = strtr($b[1], S_ACENTOS, S_NORMAIS);
        }
        return strcmp($s1, $s2);
    }
    //$j=0;
    $data = file("servicos.csv");
    foreach ($data as $i) {
        $linha = explode(";", Chop($i));
        $csv[] = $linha;
    }
    usort($csv, cmp);
    $ant = "";
    $ser = "";
    foreach ($csv as $i) {
        if ($i[1] != $ant) {
            echo "<option value=\"$i[0]\"";
            if (isset($pais) && $pais == $i[0]) {
                echo " selected";
                $ser = $i[1];
            }
            echo ">$i[1]</option>\n";
        }
        if ($ser == $i[1]) {
            $servicos[] = array($i[0], $i[2]);
        }
        $ant = $i[1];
    }
?>
</select>
</body>
</html>
END   -- index.html --

BEGIN -- servicos.csv --

1;Reino Unido;Thomweb - Thomson Directories;http://www.infospace.com/uk.thomw/
2;Reino Unido;Electronic Yellow Pages;http://www.eyp.co.uk/
3;Reino Unido;Ask Alex Directory;http://www.askalex.co.uk/
4;B?lgica;Infobel;http://www2.infobel.be/infobel/
5;Eslov?nia;Telefonski Imenik Slovenije;http://tis.telekom.si/
6;Sui?a;Swisscom;http://www.whitepages.ch/
7;Andorra;Guia Electronica - P?ginas Blancas;http://www.laguia.ad/
8;Andorra;Guia Electronica - P?ginas Amarillas;http://www.laguia.ad/gyeselluxe.asp?lang=ENG
9;Su?cia;Gula Sidorna;http://www.gulasidorna.se/main/frameset.asp
10;?ustria;Telekom Austria;http://www.etb.at/
END   -- servicos.csv --

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-07-01 15:22 UTC] sniper@php.net
Can not reproduce:

http://snaps.php.net/php4-latest.tar.gz

And please add a SHORT example next time.

 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Thu Oct 08 10:00:01 2026 UTC