Discussion: sorting in PHP.
Afficher un message
Vieux 27/03/2008, 01h58   #8
Michael Fesser
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: sorting in PHP.

..oO(amit)

>Thanks indeed for you solution using regular experession but I'm
>afraid to get into trouble later since I'm not familiar with RE yet.
>
>Any other suggestions?


Here's another one:

The strings look like CSV, so you could try to split them. Currently PHP
can only read CSV data from files, but in coming PHP versions there will
be a function to parse CSV strings. For now you could use this hackish
replacement until the official str_getcsv() becomes available:

if (!function_exists('str_getcsv')) {
function str_getcsv($input, $delimiter = ',', $enclosure = '"',
$escape = '\\') {
$fh = fopen('php://memory', 'w+');
fwrite($fh, $input);
rewind($fh);
$result = fgetcsv($fh, 0, $delimiter, $enclosure);
fclose($fh);
return $result;
}
}

With this function you can easily split your data strings and should be
able to use usort() to sort them on the 10th item.

HTH
Micha
  Réponse avec citation
 
Page generated in 0,07593 seconds with 9 queries