Why cannot you store it in the file as array and just include it. Simpler and much faster


Rishabh Gupta wrote:

Hi all,
I want to write a parser that would read a menu structure in a text
file, parse it and then turn that into an array structure. The menu
structure would use brackets to represent a new submenu and for each item in
the menu there would be some extra properties. EG:

Root
(
Sub1
(
Sub1A
Sub1B
)
Sub2
(
Sub2A
(
Sub2Aa
Sub2Ab
)
Sub2B
)
)


The parser needs to turn that menu structure into something like this:

"Root" => array
(
"Sub1" => array
(
"Sub1A",
"Sub1B",
),
"Sub2" => array
(
"Sub2A" => array
(
"Sub2Aa",
"Sub2Ab"
),
"Sub2B"
)
)


In addition to this, I need to have the additional feature of storing
addition information for each item in the menu. Thus

Root
(
Sub1 name=sub1 title="the
title 1"
(
Sub1A
Sub1B
)
Sub2
)

Would Become Something Like

"Root" => array
(
"Sub1" => array
(
"info" => array("name"=>sub1, "title"=>"the title 1"),
"" => array
(
"Sub1A",
"Sub1B",
)
),
"Sub2" => array
)


Could somebody recommend to what is the best way to implement such a
function. There are essentially two parts to this. The first part reads and
parses the text file, and the second part puts the structure into an array.
Any help would be greatly appreciated.

Many Thanks

Rishabh





--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to