You'll first want to split the string into lines, split it into sub-arrays, run through usort, and then join it all back together. For example:
function lineSplit( &$item )
{
$item = explode( '|', $item );
}
function lineSort( $item1, $item2 )
{
return strcmp( $item1[ 3 ], $item2[ 3 ] );
}
function lineJoin( &$item )
{
$item = join( '|', $item );
}
$str = '...';
// First split on the comma to get each line.
$lines = explode( ",\n", $str );
// Now split each line into subarrays
array_walk( $lines, 'lineSplit' );
// Perform the sort using a user-defined function.
usort( $lines, 'lineSort' );
// Now join the subarrays into strings.
array_walk( $lines, 'lineJoin' );
// And finally merge the lines again.
$str = join( ",\n", $lines );
Jon Benedicto
2009-08-31 17:58:47