Vanilla 1.1.1 is a product of Lussumo. More Information: Documentation, Community Support.
Hi,
I have a program that saves its preferences files in a format that looks a bit like this:
[Desc|Jack|TargetSite|[Host\|example.com\|Username\|test\|Password\|test\|]|DateTo|27/11/2006 19:17:00|]
That basically represents a structure like this:
Desc: Jack
TargetSite:
Host: example.com
Username: test
Password: test
DateTo: 27/11/2006 19:17:00
Does anyone recognise this as a common data serialisation format? I want to write a PHP script that will read and write these files, but there’s no point if one might already exist. Thanks in advance.
Jack
Looks like YAML
No, YAML looks like this:
invoice: 34843
date : 2001-01-23
bill-to: &id001
given : Chris
family : Dumars
The second code snippet was just an example of the structure, its the first snippet I’m trying to identify.
What program is it?
I’ve seen formats like that before but I’ve never seen a standards doc or reference.
Looks kinda like csv with “|” delimiters and then they introduce nest items with
“\|” I bet the easiest adaption would be to hack a csv parser.
It’s InstantSync FTP, and the files are the individual site preferences files. I may have to e-mail the developers, fnd out if they just made it up, or if its a standard.
Well, I contacted the developers and it turns out that its not a standard:
“The format is not standard, and its not public, and modifying it manually is NOT supported.”
Never mind, I will just have to figure it out myself.
Thats to bad. You might be able to use this
<?php
$row = 1;
$handle = fopen("test.csv", "r");
while (($data = fgetcsv($handle, 1000, "|")) !== FALSE) {
$num = count($data);
echo "<p> $num fields in line $row: <br /></p>\n";
$row++;
for ($c=0; $c < $num; $c++) {
echo $data[$c] . "<br />\n";
}
}
fclose($handle);
?>
Is the 4th field always the host info?
tstrokes: Is the 4th field always the host info?
No its not, and it can appear anywhere, in fact there are actually two nested sections in the full file (I only posted part of it). The only good news is that the nesting is only ever one level deep.
Yeah thats good. Having multiple levels would be hectic and cluttered.
Are you going to use php?
Yeah. I need to think about what I’m actually going to do with it, because in reality I might not actually need a reader, just a writer, which will be a lot easier. When changes need to be applied I can just overwrite the previous file. As much as a complete solution would be nice, there’s no point wasting time on code I wont use.
Something that’s a bit peculiar, if you add a pipe character into one of the top level values, it is escaped with a back slash:
[Test|This is a \| test|]
But then the pipes that split the nested details are also escaped, so if you add a pipe to one of those details, it is escaped with three pipes:
[Test|[Jack|My name \\\| is Jack|]|]
It all seems a bit oddly thought out, you would have thought that for future extensibility, nested data would follow the same format, but then, I suppose this makes it easier to parse.
I would use ruby if possible. As you probably already know it has some greater solutions for tasks like this.
1 to 12 of 12