-
Notifications
You must be signed in to change notification settings - Fork 10
/
pear-dh-ini2xml
executable file
·56 lines (41 loc) · 1.25 KB
/
pear-dh-ini2xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!@PHP-BIN@
<?php
/**
* Converts the old-style INI-language files into XML-files that
* are used from version 0.14.0+.
*
* @version $Id$
* @author Carsten Lucke <[email protected]>
*/
$frame = <<<EOT
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes" ?>
<driver-data>
<holidays>
__DATA__
</holidays>
</driver-data>
EOT;
$template = <<<EOT
<holiday>
<internal-name>__INTERNALNAME__</internal-name>
<translation>__TRANSLATION__</translation>
</holiday>
EOT;
array_shift($_SERVER['argv']);
if ($_SERVER['argc'] < 1) {
die('Call this file from command line: ini2xml.php <file-to-convert> [<file-to-convert> [...]]' . "\n");
}
foreach ($_SERVER['argv'] as $filename) {
$newFilename = str_replace('.ini', '.xml', $filename);
$contents = parse_ini_file($filename);
$_xml = '';
foreach ($contents as $internalName => $translation) {
$_tmp = str_replace('__INTERNALNAME__', $internalName, $template);
$_tmp = str_replace('__TRANSLATION__', $translation, $_tmp);
$_xml .= $_tmp;
}
$c = str_replace('__DATA__', $_xml, $frame);
$fp = fopen($newFilename, 'w');
fwrite($fp, $c, strlen($c));
}
?>