Human readable config files

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Captain Dondo

    Human readable config files

    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

    #2
    Re: Human readable config files

    Hi,

    You might try to serialize an array and deserialize it later.
    Generates a storable representation of a value



    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]

    Comment

    • Chung Leong

      #3
      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

      Comment

      • Captain Dondo

        #4
        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....

        Comment

        • Captain Dondo

          #5
          Re: Human readable config files

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



          Perfect.

          :-)

          Comment

          • Robin

            #6
            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_conten ts($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:


            For PHP 4, you could include the also easy to handle XML-Parser from the
            PEAR repository:



            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]

            Comment

            Working...