-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
116 lines (107 loc) · 3.17 KB
/
index.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php
/**
* @file
* Demonstration file of using TagConverter library.
*/
require 'vendor/autoload.php';
use writecrow\TagConverter\TagConverter;
$file = file_get_contents('demo_text.txt', FILE_USE_INCLUDE_PATH);
if (isset($_POST['text'])) {
$file = $_POST['text'];
}
include 'head.html';
echo '
<div class="container">
<h1>Tagged corpus text converter</h1>
<a href="https://github.com/writecrow/tag_converter">Source code</a>
<hr />
</div>
<div class="container">
<form action="//' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'] . '" method="POST">
<div class="row">
<div class="six columns">
<label for="text">Tagged text to be converted</label>
<textarea class="u-full-width textbox" placeholder="Place tagged text here..." name="text">' . $file . '</textarea>
</div>
<div class="six columns">
<input type="submit" name="json" value="Convert to JSON" />
<input type="submit" name="php" value="Convert to PHP" />
<input type="submit" name="xml" value="Convert to XML" />';
if (isset($_POST['text']) && isset($_POST['json'])) {
$text = TagConverter::json($_POST['text']);
$json = json_decode($text);
echo '<div><pre><code>';
echo json_encode($json, JSON_PRETTY_PRINT);
echo '</code></pre></div>';
}
elseif (isset($_POST['text']) && isset($_POST['php'])) {
$text = TagConverter::php($_POST['text']);
echo '<div><pre><code>';
print_r($text);
echo '</code></pre></div>';
}
elseif (isset($_POST['text']) && isset($_POST['xml'])) {
$text = TagConverter::xml($_POST['text']);
echo '<div><pre><code>';
// Deal with XML-specific non-visible space for display.
$text = str_replace('', '', $text);
echo htmlspecialchars($text);
echo '</code></pre></div>';
}
echo '
</div>
</div>
</form>
<h3>Design & behavior</h3>
<ol>
<li>Tags must be wrapped in <code><</code> and <code>></code></li>
<li>Tag names and tag values may only alphanumeric characters, spaces, underscores, and hypens.</li>
<li>Tag names must be separated from tag values by a <code>:</code></li>
<li>Spaces at the beginning at end of tag names or tag values are ignored; spaces within tag values will be preserved</li>
<li>Items with multiple values may be indicated by a pipe (|) character or semicolon (;)</li>
<li>Everything not wrapped in <code><</code> and <code>></code> will be considered "text"</li>
</ol>
<table>
<thead>
<tr>
<th>Status</th>
<th>Tag Example</th>
<th>Explanation</th>
</tr>
</thead>
<tbody>
<tr>
<td>Good</td>
<td><code><MyTag:SomeText></code></td>
<td></td>
</tr>
<tr>
<td>Good</td>
<td><code><My Tag:Some Text></code></td>
<td>Spaces in tag names & values OK</td>
</tr>
<tr>
<td>Good</td>
<td><code>< My Tag : Some Text ></code></td>
<td>Spaces padding tag names & values OK</td>
</tr>
<tr>
<td>Good</td>
<td><code>< My-Tag : Some_Text ></code></td>
<td>Underscores & hyphens OK</td>
</tr>
<tr>
<td>Good</td>
<td><code>< My-Tag : First value | Second value></code></td>
<td>Pipe or semicolon used to indicate multiple values</td>
</tr>
<tr>
<td>Bad</td>
<td><code>< My/Tag : Some:Text ></code></td>
<td>Other characters not OK</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>';