I seem to have done something stupid but I can’t see the wood for the trees.
I have the code below which steps though an array and divides groups of array elements into a string. It should iterate through this array 15 times and concatenate the output string. It only uses the data from the last record not the previous 14 in the output string.
Any thoughts most welcome.
[php]
//Now get the data for each individual
for ($i=$ind[0];$i<$ind[14];$i++){
//echo $persons[$i]."
";
//get the id
if (strpos($persons[$i],“0 @”)!==false){
//if (strpos($record,“0 @I”)!==false){
$s = explode("@",$persons[$i]);
for($k=1;$k<=count($s)-1;$k+=2){
$data .= $s[$k]." “;
$rec_id = “P “.$s[$k].”=”;
}
}
//get name
if (strpos($persons[$i],“1 NAME”)!==false){
$n = str_replace(’/’,’’,$persons[$i]);
$n = str_replace(‘1 NAME ‘,’’,$n);
$data .= $n.” “;
$nt = $n;
$pname = $n;
//continue;
}
//Get Sex
if (strpos($persons[$i],“1 SEX”)!==false){
$n = str_replace(‘1 SEX ‘,’’,$persons[$i]);
$data .= $n.” “;
$sx = trim(strtolower($n));//.”(".$row.",2):";
$row++;
}
//Get Birth
if (strpos($persons[$i],“1 BIRT”)!==false){
$bf = “y”;//Has a birth fact
}
if ((strpos($persons[$i],“2 DATE”)!==false) && $bf ==“y”){
$n = str_replace(‘2 DATE ‘,’’,$persons[$i]);
$gotdate = “y”;
$data .= “B: “.$n.” “;
$b_date = “- B:”.trim($n).” in “;
}
if (((strpos($persons[$i],“2 PLAC”)!==false) && $bf ==“y”) && $gotdate ==“y”){
$n = str_replace('2 PLAC ', ‘’, $persons[$i]);
$data .= $n;
$b_place = $n;
if (empty($b_place)){$b_place =” “;};
$bf = “n”;
}
//Get Death
if (strpos($persons[$i],“1 DEAT”)!==false){
$df = “y”;//Has a death fact
}
if ((strpos($persons[$i],“2 DATE”)!==false) && $df ==“y”){
$n = str_replace(‘2 DATE ‘,’’,$persons[$i]);
$data .= “D: “.$n.” “;
if (empty($n)){$n=” “;};
$d_date = “- D:”.trim($n).” in “;
}
if ((strpos($persons[$i],“2 PLAC”)!==false) && $df ==“y”) {
$n = str_replace('2 PLAC ', ‘’, $persons[$i]);
$data .= $n . "
“;
if (empty($n)){$n=” “;};
$d_place = $n;
$df = “n”;
}
}
if (empty($d_date)){$d_date=” “;};
if (empty($d_place)){$d_place=” “;};
//Now construct note field
$p_note =”= “.trim($pname).” was born “.substr($b_date,4).trim($b_place);
if (($d_date)!==” “){$p_note .=” and died “.substr($d_date,4).$d_place;}
//now write this record to string
$opf .= $rec_id.$sx.”(”.$row.”,2):”.$pname.$b_date.$b_place.$d_date.$d_place.”\r\n".$p_note;
[/php]