Topic: Comma delimited file

I have a comma delimited text file with several records. A typical record looks like this:

Jim,Smith,1234 Main Street,Anytown,NY,12345,206,123-3456

I need to read the file andd then output the data (name and phone number) in a two columm table like this:

Smith, Jim        (206) 123-3456

The data also needs to be sorted by last name.

I assume I will be using an array, but I'm not sure how to do it.

If you can help me, email me at grz@wi-net.com.

Thanks,

Andrew

Thumbs up

Re: Comma delimited file

Hope it helps !!!

<?php
$sContents    =    "Jim,Smith,1234 Main Street,Anytown,NY,12345,206,123-3456\n";
$sContents    .=    "Aneesh,R,1234 Main Street,Anytown,NY,12345,206,123-3456\n";
$sContents    .=    "Sambhu,S,1234 Main Street,Anytown,NY,12345,206,123-3456";

foreach( explode("\n", $sContents) as $k=>$sContent ){
    $arrValues    =    explode( ",", $sContent );
    $arrGlobal[$arrValues[1]][]    =    $arrValues[1] ."," . $arrValues[0] ."," . $arrValues[7] ;
}
sort( $arrGlobal );
foreach( $arrGlobal as $Global ){
    echo $Global[0] ."<br>";
}
?>

Thumbs up