Q:

CSV to Array in PHP:

I've loaded a CSV into an PHP array. csv[0] has names, and csv[4] has a biography. the biography spans several lines where csv[0] is null.  The code below is displaying the correct names, but not the complete biography
    public function test($let){
    $csv = $this->readCSV("data\AlphaIndex1N.csv");
    $arraySize=sizeof($csv);
    foreach ($csv as $key => $value) {
      if ($value === null) {
        $csv[$key] = "NULL";
      }
    }
    $let = strtoupper($let);    
    for($i=1; $i<$arraySize; $i++)
    {   $n=0;
        if(substr($csv[$i][0], 0, 1) == $let){
            echo $csv[$i][0].', -->'.$csv[$i][4];
            $n = $i++;
            while($csv[$n][0] != "NULL"){
                echo $csv[$n][4]. " ";
                $n=$n+1;
            }
            echo '</br></br>';
        }
    }
}

csv:
,FAMILY SURNAMES & Chart #s,RESIDENCES,Marriage/Immigr Date or 1st in NE,DESCENDANTS^ VITALS^ & SOURCES
ADAMS #221,ADAMS #221,Somersetshire^ England,1640,John ADAMS b/d Somersetshire Eng; m. Agnes ___. [per Savage:  John^ a tailor^ was in Newbury^ MA^ by 1640.]  
,SQUIRE,Braintree,,Henry ADAMS b. Somerset^ Eng. abt 1583; orig. proprietor of Braintree;  m. Eng.^ 1609^ Edith SQUIRE; d. Braintree 1646.  Ancestor of Pres. John Adams.
,,Braintree^ Medfield,,Edward ADAMS of Medfield^ b. Kingweston/Somerset^ Eng. 1629; m. 1652 in MA^ Lydia PENNIMAN. Edward was selectman and Rep in first Gen Courts. In Braintree by 1689.
,PENNIMAN,Medfield,1652,Jonathan ADAMS b. Medfield 1655; m. 1678 Mary ELLIS; d. Medfield 1718.
,,Newbury Medfield,,Mary ADAMS b. Medfield 1681; m. 1708 Henry2 SMITH; he d. Medfield 1743.
,ELLIS,,1678,[That couple had dau Mary SMITH b. Medfield 1709; m. 1728 David CLARK; d. Medfield 1770. 
,SMITH,Hawley,1708,Then their son John CLARK b. CT abt 1736; m. Sarah ___; d. Goshen 1822; 
,CLARK,Charlemont,1728,then their dau Mary/Molly CLARK m. Goshen 1791^ Ebenezer PUTNEY.
,PUTNEY,Charlemont,1791,Mary/Molly and Ebenezer had dau Sarah/Sally PUTNEY b. Ashfield 1792; m. 1812 Levi H. ELDRIDGE; res Hawley. 
,ELDRIDGE,Devonshire^ Eng,1812,This couple had Roswell H. ELDRIDGE^ who m. 1847 Eliza Hawks LONGLEY; d. Charlemont 1891. 
,LONGLEY,,1847,These were the parents of Henrietta Maria ELDRIIDGE^ who m. 1895 Oscar Carter AVERY.]
,AVERY,Newbury Andover,1895,See ADAMS GENEALOGY at CTHS.    GMN 10:2; 10:3; 2:3; 3:13; GMN 304
ADAMS #120,ADAMS #120,,--,Peter ADAMS b. Eng.; d. Ottery St. Mary/Devon^ Eng.  
,,Westford,,Robert ADAMS b. Devonshire^ Eng. 1602; m. Eng.^ Eleanor WILMOTT; d. Newbury^ MA 1682.
,WILMOTT,Charlestown NH,By 1682,Elizabeth ADAMS b. 1641/2; m. MA^ Edward PHELPS of Andover. Edward d. Andover 1689. (Their son
,PHELPS,Groton^ MA,Abt 1660,John b. Newbury 1657^ was k by Inds at Scarborough 1677.)
,,Groton^ MA,,[This couple had dau Eleanor PHELPS b. Newbury? 1660; m. Andover 1687 William CHANDLER; d. Westford aft 1728.
,CHANDLER,Groton^ MA,1687,Then their dau Eleanor CHANDLER b. Andover 1695; m. Seth WALKER; d. Charlestown^ NH 1769. 
,WALKER,Hawley,By 1724,That couple had dau Mary WALKER b. Groton^ MA 1724; m. abt 1743 Joseph LONGLEY; d. Groton 1776. 
,LONGLEY,Charlemont,By 1746,Their son Edmund1 LONGLEY b. Groton^ MA 1746; m. Alice LAWRENCE; 
,LAWRENCE,,By 1779,then that couple had son Edmund2 LONGLEY b. Groton^ MA 1779; m. Olive FIELD; 
,FIELD,,,then their dau Eliza Hawks LONGLEY b. Hawley 1827; m. 1847 Roswell ELDRIDGE; 
,ELDRIDGE,,1847,these were the parents of Henrietta Maria ELDRIDGE^ who m. 1895 Oscar C. AVERY of Charlemont.]
,O.C. AVERY,,1895,

desired output:
ADAMS = John ADAMS b/d Somersetshire Eng; m. Agnes ___. [per Savage:  John, a tailor, was in Newbury, MA, by 1640.]  
Henry ADAMS b. Somerset, Eng. abt 1583; orig. proprietor of Braintree;  m. Eng., 1609, Edith SQUIRE; d. Braintree 1646.  Ancestor of Pres. John Adams.
Edward ADAMS of Medfield, b. Kingweston/Somerset, Eng. 1629; m. 1652 in MA, Lydia PENNIMAN. Edward was selectman and Rep in first Gen Courts. In Braintree by 1689.
Jonathan ADAMS b. Medfield 1655; m. 1678 Mary ELLIS; d. Medfield 1718.

MY OUTPUT:
ADAMS #221, -->John ADAMS b/d Somersetshire Eng; m. Agnes ___. [per Savage: John, a tailor, was in Newbury, MA, by 1640.] 

ADAMS #120, -->Peter ADAMS b. Eng.; d. Ottery St. Mary/Devon, Eng. 

A:

This is probably not the most elegant code, but given the transformation from Word to Excel to csv to array, it worked
    $file_handle = fopen($csvFile, 'r');
    $array = array();$wholeArray = array(); $line_of_text = "";$set = false;$name="";
    $r=0;
    while (!feof($file_handle)){
        $error = false;
        if(!$set){$array = fgetcsv($file_handle, 1536); $set = true; }
        else{$array = $line_of_text; $line_of_text="";}
        if($line_of_text == ""){$line_of_text = fgetcsv($file_handle, 1536);}

        while ($line_of_text[0] == 'NULL'){
            for($i=1; $i<5; $i++){
                try{$array[$i] .= '+'.$line_of_text[$i];
                    $array[$i] = str_replace(chr(94), ",", $array[$i]);
                }
                catch (Exception $e) { echo "error in record ".$name." @".$i." / "; $error = true; break;}
            }
            $line_of_text = fgetcsv($file_handle, 1536);
            $set = true;
        }
        if($error){continue;}
        //$this->printArray($array);    
        $name = $array[0]; //FOR ERRORS

        array_push($wholeArray,$array);
        if($r <= 50){$this->arrayToMySQL2($array);} // ab=74 c=38 def=33
        $r++;
    }
    fclose($file_handle);

