Connecting Tech Pros Worldwide Forums | Help | Site Map

Human readable config files

Captain Dondo
Guest
 
Posts: n/a
#1: Apr 14 '06
I am working on an embedded platform. Disk storage is at a premium, so
I am trying not to add any more stuff....

I am reading and writing some data that the user enters through a
webform. The form is an operations schedule for a piece of equipment.

Basically, the schedule consists of repeated actions by the machine, and
it is very simple:

%f %f %d %d %d %d %d

repeated about 10 or 15 times.

I will be storing the data in associative arrays, so I would like a
simple way to write the data in a format easily read by a human.

So, instead of the simple line of numbers, I would like something like this:

< Schedule
< Line
< From %f >
< To %f >
< Op1 true >
< Op2 true >
< Op3 false >
< Op4 true >
</ Line>
.... [more lines as needed]
</ Schedule>

I was thinking of XML, but it looks as though XML uses external libs and
is fairly complex to use in PHP....

Since the data is stored in an associative array basically using the
above structure, is there a way to dump an array to file and then read
it back?

Something like print_r, but using file ops and also a read_r to read it
into the array?

Bascially, I am looking for the simplest way to create something that
looks sort of like XML....

Oleg Romanenko
Guest
 
Posts: n/a
#2: Apr 14 '06

re: Human readable config files


Hi,

You might try to serialize an array and deserialize it later.
http://www.php.net/serialize


Captain Dondo wrote:[color=blue]
> I am working on an embedded platform. Disk storage is at a premium, so
> I am trying not to add any more stuff....
>
> I am reading and writing some data that the user enters through a
> webform. The form is an operations schedule for a piece of equipment.
>
> Basically, the schedule consists of repeated actions by the machine, and
> it is very simple:
>
> %f %f %d %d %d %d %d
>
> repeated about 10 or 15 times.
>
> I will be storing the data in associative arrays, so I would like a
> simple way to write the data in a format easily read by a human.
>
> So, instead of the simple line of numbers, I would like something like
> this:
>
> < Schedule
> < Line
> < From %f >
> < To %f >
> < Op1 true >
> < Op2 true >
> < Op3 false >
> < Op4 true >
> </ Line>
> ... [more lines as needed]
> </ Schedule>
>
> I was thinking of XML, but it looks as though XML uses external libs and
> is fairly complex to use in PHP....
>
> Since the data is stored in an associative array basically using the
> above structure, is there a way to dump an array to file and then read
> it back?
>
> Something like print_r, but using file ops and also a read_r to read it
> into the array?
>
> Bascially, I am looking for the simplest way to create something that
> looks sort of like XML....[/color]
Chung Leong
Guest
 
Posts: n/a
#3: Apr 14 '06

re: Human readable config files



Captain Dondo wrote:[color=blue]
> I am working on an embedded platform. Disk storage is at a premium, so
> I am trying not to add any more stuff....
>
> I am reading and writing some data that the user enters through a
> webform. The form is an operations schedule for a piece of equipment.
>
> Basically, the schedule consists of repeated actions by the machine, and
> it is very simple:
>
> %f %f %d %d %d %d %d
>
> repeated about 10 or 15 times.
>
> I will be storing the data in associative arrays, so I would like a
> simple way to write the data in a format easily read by a human.
>
> So, instead of the simple line of numbers, I would like something like this:
>
> < Schedule
> < Line
> < From %f >
> < To %f >
> < Op1 true >
> < Op2 true >
> < Op3 false >
> < Op4 true >
> </ Line>
> ... [more lines as needed]
> </ Schedule>
>
> I was thinking of XML, but it looks as though XML uses external libs and
> is fairly complex to use in PHP....
>
> Since the data is stored in an associative array basically using the
> above structure, is there a way to dump an array to file and then read
> it back?
>
> Something like print_r, but using file ops and also a read_r to read it
> into the array?
>
> Bascially, I am looking for the simplest way to create something that
> looks sort of like XML....[/color]

How about the WDDX functions? http://fi.php.net/wddx

Captain Dondo
Guest
 
Posts: n/a
#4: Apr 14 '06

re: Human readable config files


Chung Leong wrote:
[color=blue][color=green]
>>Bascially, I am looking for the simplest way to create something that
>>looks sort of like XML....[/color]
>
>
> How about the WDDX functions? http://fi.php.net/wddx
>[/color]

Wow! That looks really interesting....

Do you happen to know if there is a C parser for wddx? Google finds
nothing...

My backend is written in C....
Captain Dondo
Guest
 
Posts: n/a
#5: Apr 14 '06

re: Human readable config files


Thanks, and never mind; I found XML_for_morons like me:

http://keithdevens.com/software/phpxml

Perfect.

:-)
Robin
Guest
 
Posts: n/a
#6: Apr 15 '06

re: Human readable config files


Hi,

I hope I didn't get you wrong, but assuming you don't need any DOM
operations, you can just build a string containing your XML and write it
to a file with file_put_contents($filename).

To read it, you could use (PHP 5-only) the build-in SimpleXML-API, which
is very fast and easy to handle for reading purposes:
http://www.php.net/manual/en/ref.simplexml.php

For PHP 4, you could include the also easy to handle XML-Parser from the
PEAR repository:
http://www.php.net/manual/en/ref.simplexml.php


Captain Dondo wrote:[color=blue]
> I am working on an embedded platform. Disk storage is at a premium, so
> I am trying not to add any more stuff....
>
> I am reading and writing some data that the user enters through a
> webform. The form is an operations schedule for a piece of equipment.
>
> Basically, the schedule consists of repeated actions by the machine, and
> it is very simple:
>
> %f %f %d %d %d %d %d
>
> repeated about 10 or 15 times.
>
> I will be storing the data in associative arrays, so I would like a
> simple way to write the data in a format easily read by a human.
>
> So, instead of the simple line of numbers, I would like something like
> this:
>
> < Schedule
> < Line
> < From %f >
> < To %f >
> < Op1 true >
> < Op2 true >
> < Op3 false >
> < Op4 true >
> </ Line>
> ... [more lines as needed]
> </ Schedule>
>
> I was thinking of XML, but it looks as though XML uses external libs and
> is fairly complex to use in PHP....
>
> Since the data is stored in an associative array basically using the
> above structure, is there a way to dump an array to file and then read
> it back?
>
> Something like print_r, but using file ops and also a read_r to read it
> into the array?
>
> Bascially, I am looking for the simplest way to create something that
> looks sort of like XML....[/color]
Closed Thread