roydukkey Posted August 27, 2008 Share Posted August 27, 2008 I have a string [block of text from a file via fopen()] that I would like to split into a multi-dimensional array. Here the contents of the file that is opened: Father { son child { bob john jim } } mother { daughter kin } bigfoot { hairy kisses } How can I use preg_split() to result in the following array or if there is a better way how can this be done: Array ( [ 0 ] => Father ( [ 0 ] => son [ 1 ] => child ( [ 0 ] => bob [ 1 ] => john [ 2 ] => jim ) ) [ 1 ] => mother ( [ 0 ] => daughter [ 1 ] => kin ) [ 2 ] => bigfoot ( [ 0 ] => hairy [ 1 ] => kisses ) ) Thanks for your help. roydukkey Quote Link to comment Share on other sites More sharing options...
nrg_alpha Posted August 27, 2008 Share Posted August 27, 2008 While I'm not sure about the multidimensional array part, instead of using fopen, you can use file(filepath and file name here). This opens a file and extracts its contents into an array. I'm guessing that depending on what your file is structured like to begin with would determine the array that file() creates.. The from there, you can list the array via foreach(), then if you feel the need to break if down further, perhaps use preg_split (not entirely sure if this last bit is feasable). You can read up on file() here: http://us2.php.net/manual/en/function.file.php Quote Link to comment Share on other sites More sharing options...
roydukkey Posted August 28, 2008 Author Share Posted August 28, 2008 Ok, sounds good...? I'll do some more learning and post back if I need anything more. Thank you very much for you help, nrg_alpha. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.