You are here: Parsing tab formatted hierarchical strings into a tree « PHP Programming Language « IT news, forums, messages
Parsing tab formatted hierarchical strings into a tree

Posted by Kailash Nadh on 09/28/97 12:01

Hello all.
I have this tab formatted hierarchical structure.
--------------------
0 A
1 B
2 C
2 D
1 E
--------------------

Every line has a string intended to its depth with tabs. (The numbers
in the above example are the number of tabs intending that line and
are not present in the actual data)

I need to parse the above structure into a tree (multi-dimensional
array), for eg:
Array
(
[A] => Array
(
[B] => Array
(
[C] =>
[D] =>
)
[E] =>
)
)

I have this loop that parses each line and has the following for every
line,
$depth = (number of tabs) and $key = (A, B etc..)

So the string in each line is the KEY of the array / tree. Needn't
worry about the value.

This is pretty simple, but I just can't get my head around it. Could
anyone throw some light on this issue?

Thank you.

--
Kailash Nadh | http://kailashnadh.name

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация