I am parsing a genealogy test file to extract some data from it to use elsewhere.
This is currently the code that I have and it is getting the name and the reference fine but not getting the sex of the person.
$file_handle = fopen($fn, "r");
while(!feof($file_handle)){ $line = fgets($file_handle);
if ((strpos($line, "0 @") !== false) && (strpos($line,"INDI")!==false)){
$ref = explode("@",$line);
$line = fgets($file_handle);
if (strpos($line,"1 NAME") !==false){$name = str_replace("1 NAME ","",$line);$na = explode("/",$name);}
if (strpos($line,"1 SEX") !==false){$sx= str_replace("1 SEX ","",$line);}
echo $ref[1]." ".$na[0]." ".$na[1]." ".$sx."<br>";
}
}
}
fclose;
This is an example of a record from the file
0 @I3@ INDI
1 NAME Reginald William /Spencer/
2 GIVN Reginald William
2 SURN Spencer
1 SEX M
Can anyone please give me a clue as to why the Sex is not being read?