rblampain
asked on
flat file and PHP array
I need to make a script that creates a multi dimensions array using "forms". The user would be asked to define the number of elements and dimensions and provide keywords for each, this can go down 5, 6 or 7 levels (array of arrays of arrays of...). This needs to be saved as a flat file
Then I need a second script that can read the file and reconstruct the array as it was intended.
I can't visualize how to do this, could anyone suggest scripts?
Example of the keywords hierarchy I am talking about:
Primary keywords
("Copyright","About the author","Credits","Preface ","Acknowl edgments", "Contents" ,"Appendic es","Index ","etc")
Secondary keywords
Copyright ("Liability","Waranty","Tr ademark"," etc")
About the author ("Identity"," Address","Qualifications", "etc")
Credits ("Acquisition","Developmen t","Techni cal","Prod uction","e tc")
Preface ("comment1","comment2","et c")
...
Contents ("part1","part2","etc")
etc
Level3 keywords
...
Credits ["Acquisition"] ("research1","research2"," etc")
Contents ["Part1"] ("tome1","tome2","etc")
....
Level4 keywords
...
Contents ["part1"]["tome1"] ("chapter1","chapter2","et c")
...
etc
Level5 keywords
etc
Thank you for your help.
Then I need a second script that can read the file and reconstruct the array as it was intended.
I can't visualize how to do this, could anyone suggest scripts?
Example of the keywords hierarchy I am talking about:
Primary keywords
("Copyright","About the author","Credits","Preface
Secondary keywords
Copyright ("Liability","Waranty","Tr
About the author ("Identity"," Address","Qualifications",
Credits ("Acquisition","Developmen
Preface ("comment1","comment2","et
...
Contents ("part1","part2","etc")
etc
Level3 keywords
...
Credits ["Acquisition"] ("research1","research2","
Contents ["Part1"] ("tome1","tome2","etc")
....
Level4 keywords
...
Contents ["part1"]["tome1"] ("chapter1","chapter2","et
...
etc
Level5 keywords
etc
Thank you for your help.
I have to agree witch cracky. XML is the way to go. Use either the xml functions provided by PHP or the sourceforge class that cracky mentioned.
For parsing the array, you can also write a recursive function that calls itself when it finds an array in an array.
For parsing the array, you can also write a recursive function that calls itself when it finds an array in an array.
ASKER
Thanks to both. I know nothing about xml, I quick search shows there is a lot I would have to learn and I just wouldn't have the time.
Any suggestion, any example?
Any suggestion, any example?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I was thinking of an easier way to store it in a file, such as a delimited text file for example rather than XML, however it would no doubt be a pain and probably unsuited to the types of data you wish to store, so i'd definately go with cracky's idea of using serialize() and unserialize() i'd never looked at these function before, but I'm sure glad I read this post, thanks for helping me also cracky :)
Cheers
Cheers
Serialize is definetly the way to go. The best simplest solutions are often the best. Go cracky!
ASKER
By popular demand.
I still have to try it, I'm slowly coming to it because other solutions are not as simple as they look.
I still have to try it, I'm slowly coming to it because other solutions are not as simple as they look.
http://phpxmlclasses.sourceforge.net
I would then use one of the parse classes to read the XML file back and populate the array to do with as you wish.
If you don't know how deep the arrays go, then you need to perform a check at each level to see if the next node is an array with is_array(). Then you would use something like array_walk() to perform operations on each iteration.