-
Notifications
You must be signed in to change notification settings - Fork 0
/
remove_group.php
61 lines (44 loc) · 1.2 KB
/
remove_group.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
/**
* remove unnecessary group tag in SVG
*
* @access public
* @author Yohei Minami
* @facebook yohei.minami
* @twitter mi73
* @create 2012/10/15
* @version 0.0.1
**/
switch ($argc) {
case 1:
echo "Require INPUT_FILE_NAME OUTPUT_FILE_NAME argument.\r\n";
break;
case 2:
echo "Require INPUT_FILE_NAME OUTPUT_FILE_NAME argument.\r\n";
break;
default:
$inputFileName = $argv[1];
$outputFileName = $argv[2];
$file = file($inputFileName);
$g_flag = array();
$output = "";
$l = count($file);
for ($i = 0; $i < $l; $i++) {
if (preg_match("/<g>/", $file[$i])) {
$g_flags[] = true;
} elseif (preg_match("/<g /", $file[$i])) {
$g_flags[] = false;
$output .= $file[$i];
} elseif (preg_match("/<\/g>/", $file[$i])) {
$flag = array_pop($g_flags);
if ($flag == false) {
$output .= $file[$i];
}
} else {
$output .= $file[$i];
}
}
file_put_contents($outputFileName, $output);
break;
}
?>