Recursive File Parser
Posted: Fri Aug 05, 2005 4:28 pm
Hi guys, I'm working on a family tree web site. Here are the basics. Every person gets a file, with a list of thier children and thier filenames in it (along with other info). What I need to do, is write a bit of code that goes through all the files by following the links. This will be used for several things (drop down menu of all people in the tree, drawing of the complete table, etc.) Now the catch is I don't know how many generations down it will end up going, and it would be essentially the same code anyway, so how could I go about looping it to go through and find all the people at once? Here's what I have so far, but its not exactly complete.
and here is an example file:
Thanks for the help!
Code: Select all
$f = fopen('$filename', "r");
$c = fgets($f);
$c = fgets($f);
while (!feof($f)) {
$c = fgets($f);
$filename = str_replace("\n", "", fgets($f));
$realname = str_replace("\n", "", fgets($f));
echo "<option value='" . $filename . "'>" . $realname . "\n"; //menu in this case
$g = fopen($filename, "r"); //this has to somehow loop back to the top without forgetting what the last file and the one before that was
}and here is an example file:
Code: Select all
3 //file type identifyer
John Smith //primary perant
1123267570 //file name for this kid
Kid One //kid's name
1123267491 //file name for this kid
Kid Two //kid's name
1123264571 //file name for this kid
Kid Three //kid's name
3 //marker of end of child list
other info
other info
other info