-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathjson_pretty_print.php
35 lines (25 loc) · 1.05 KB
/
json_pretty_print.php
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
<?php
// Copyright © 2013 by Ezer IT Consulting. All rights reserved. E-mail: [email protected]
// This is for command line usage
// Usage:
// php prop2json.php <properties file>
// Outputs a JSON version of the Java properties file (localization file) to stdout.
error_reporting(E_ALL|E_STRICT);
ini_set('display_errors', 'stderr');
ini_set('track_errors', true);
mb_internal_encoding('UTF-8');
if (($_SERVER['argc']!==2 && $_SERVER['argc']!==3) || ($_SERVER['argv'][1]!=='-p' && $_SERVER['argv'][1]!=='-u')) {
print "Usage: php json_pretty_print.php (-p|-u) [<input file>]\n";
print " -p for pretty\n";
print " -u for ugly\n";
die;
}
$filename = $_SERVER['argc']===3 ? $_SERVER['argv'][2] : 'php://stdin';
$input = @file_get_contents($filename) or die ("Failed opening file {$filename}:\nError was '$php_errormsg'\n");
$props = json_decode($input);
if (is_null($props))
die("Error in JSON input\n");
if ($_SERVER['argv'][1]==='-p')
print(json_encode($props, JSON_PRETTY_PRINT));
else
print(json_encode($props));