473,325 Members | 2,792 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

config file parse ?

Hi all,

I wonder if someone on the list can offer a suggestion as to how I can
parse a config file that has the form:

group1
name1
name2

group2
name3
name4

group3
name5
name6
name7
name8

....

I need to create a web interface to allow users to add/remove and
generally modify the above config file.

the name[*] is preceeded by 4 spaces and not a tab.

Does anyone have any suggestions ?

Many thanks
Tonino

Oct 23 '06 #1
2 1482
Tonino Greco wrote:
Hi all,

I wonder if someone on the list can offer a suggestion as to how I can
parse a config file that has the form:

group1
name1
name2

group2
name3
name4

group3
name5
name6
name7
name8

...

I need to create a web interface to allow users to add/remove and
generally modify the above config file.

the name[*] is preceeded by 4 spaces and not a tab.

Does anyone have any suggestions ?

Many thanks
Tonino
Hi Tony,

Read the file into some variable.
$file = file_get_contents ("/path/to/your/file");

// find the double newlines
$groupsArr = explode("\n\n",file);

// $groupsArr[0] now contains:
//group1
// name1
// name2

Depending on the structure you have in mind you can now continue with the
seperate groups like this (just an example)

In this example all groups are stored associatively in $myGroups

$myGroups = array();
foreach ($groupsArr as $oneGroup){
$lines = explode("\n",$oneGroup);
// first line contains groupname
$myGroup[$line[0]] = array();

// put the names in, but not the first
for($i=1;$i<count($lines);$i++){
$myGroup[$line[0]][] = trim($lines[$i]);
}
}

to view the result:
<pre>
<? print_r($myGroups); ?>
</pre>
Not tested.

Good luck,

Regards,
Erwin Moller
Oct 23 '06 #2
hi,
Not tested.

Good luck,
thanks - I think that pushed me in the right direction. I used array
of arrays to store the group names in the first array and then each
element of the array has an array of the names.

This way I can array_push new items and do as I please.

Thanks for the help
Tonino

Oct 23 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Maxim Khesin | last post by:
I want to have a config file with my python proggie, satisfying the following requirements: 1) support key->(value, default) 2) simple and intuitive to read and edit 3) easyly readable into a...
4
by: Patrick | last post by:
Hi I want tu use an app.config like the example below. The problem is, that i don't know how many Action-Tags there will be, because this can be changed by the user. When using...
5
by: qqcq6s59 | last post by:
Hi all I am a newbie and I just saw a ongoing thread on Fileprocessing which talks abt config parser. I have writen many pyhton program to parse many kind of text files by using string module and...
9
by: Mantorok Redgormor | last post by:
If I am parsing a config file that uses '#' for comments and the config file itself is 1640 bytes, and the format is VARIABLE=VALUE, is it recommended to use a) fgetc (parse a character at a...
1
by: Mike Sharp | last post by:
Hi all, I have a few questions. 1. Is there a practical maximum size for a web.config file? Point of diminishing returns? My reason for asking is that I am storing a fairly large amount of...
16
by: Timm | last post by:
I'm trying to use ASP objects (basically formed and populated based on Web.Config settings) and I want to use them in a different non-asp program with minimal reprogramming. So, my question is how...
0
by: Werner Elflein | last post by:
Hi! I tried to use the PEAR class Config.php to parse a XML configuration file which looks like <?xml version="1.0" encoding="utf-8"?> <configuration> <section> <item1>value1</item1>...
20
by: tomerfiliba | last post by:
hey i've been seeing lots of config-file-readers for python. be it ConfigObj (http://www.voidspace.org.uk/python/configobj.html) or the like. seems like a trend to me. i came to this conclusion...
4
by: Ignoramus6539 | last post by:
There were some strange requests to my server asking for config.php file (which I do not have in the requested location). I did some investigation. Seems to be a virus written in perl,...
21
by: FutureShock | last post by:
I have just recently started to use OOP for my web applications and am running into some head scratching issues. I wanted to have a separate file for all my configuration variables. Some of them...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.