-
Notifications
You must be signed in to change notification settings - Fork 34
/
demo.php
195 lines (171 loc) · 4.9 KB
/
demo.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<?php
header('Content-type: text/html; charset=utf-8');
$text = str_replace(array("\r", "\n"), ' ', <<<EOF
Dorothy lived in the midst of the great Kansas prairies, with Uncle
Henry, who was a farmer, and Aunt Em, who was the farmer's wife. Their
house was small, for the lumber to build it had to be carried by wagon
many miles. There were four walls, a floor and a roof, which made one
room; and this room contained a rusty looking cookstove, a cupboard for
the dishes, a table, three or four chairs, and the beds. Uncle Henry
and Aunt Em had a big bed in one corner, and Dorothy a little bed in
another corner. There was no garret at all, and no cellar--except a
small hole dug in the ground, called a cyclone cellar, where the family
could go in case one of those great whirlwinds arose, mighty enough to
crush any building in its path. It was reached by a trap door in the
middle of the floor, from which a ladder led down into the small, dark
hole.
EOF
);
$source = isset($_REQUEST['source']) ? $_REQUEST['source'] : $text;
$language = isset($_REQUEST['language']) ? $_REQUEST['language'] : 'en-us';
$languages = array(
'af' => 'Afrikaans'
, 'zh-latn-pinyin' => 'Chinese - Pinyin'
, 'da' => 'Danish'
, 'nl' => 'Dutch'
, 'en-us' => 'English - American'
, 'en-gb' => 'English - British'
, 'de' => 'German'
, 'fi' => 'Finnish'
, 'fr' => 'French'
, 'id' => 'Indonesian'
, 'it' => 'Italian'
, 'la' => 'Latin'
, 'no' => 'Norwegian'
, 'pl' => 'Polish'
, 'pt' => 'Portuguese'
, 'ru' => 'Russian'
, 'sl' => 'Slovenian'
, 'es' => 'Spanish'
, 'sv' => 'Swedish'
, 'tr' => 'Turkish'
);
asort($languages);
// phpSyllable code
require_once __DIR__ . '/vendor/autoload.php';
\Vanderlee\Syllable\Syllable::setCacheDir(__DIR__ . '/cache');
\Vanderlee\Syllable\Syllable::setLanguageDir(__DIR__ . '/languages');
$syllable = new \Vanderlee\Syllable\Syllable($language);
?>
<html>
<head>
<title>phpSyllable</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<style>
* {
font-family: 'Segoe UI', Verdana, Arial, Helvetica, sans-serif;
font-size: 14px;
}
html {
padding: 1em 2em;
}
h1, h2, h3, h4, h5, h6 {
margin: 0 0 10px 0;
}
h1 {
font-size: 180%;
}
h4 {
font-size: 140%;
}
h2 {
font-size: 140%;
}
h5 {
font-size: 120%;
}
h3 {
font-size: 120%;
}
h6 {
font-size: 110%;
}
h4, h5, h6 {
font-weight: normal;
font-style: italic;
font-family: Georgia, Times, "Times New Roman", serif;
color: #666;
}
.example {
text-align: justify;
border: solid 1px silver;
padding: 1em;
width: 180px;
float: left;
margin-right: 1em;
}
.debug-hyphen {
background-color: #fc0;
padding: 0 .2em;
margin: 0 .1em;
}
hr {
border: solid 1px #ccc;
margin: 2em;
}
</style>
</head>
<body>
<h1>phpSyllable</h1>
<h4>PHP Hyphenation library based on Frank Liang's algorithm used in TeX.</h4>
<form method="POST">
<div>
<label>
<select name="language">
<?php foreach ($languages as $value => $name) { ?>
<option value="<?php echo $value; ?>" <?php echo $value == $language ? 'selected="selected"' : '' ?>><?php echo $name; ?></option>
<?php } ?>
</select>
</label>
</div>
<div>
<label>
<textarea name="source" cols="80" rows="10"><?php echo $source; ?></textarea>
</label>
</div>
<div>
<button>Hyphenate</button>
</div>
</form>
<hr/>
<div class="example">
<h2>Source</h2>
<h5>Without hyphens</h5>
<?php
echo nl2br($source);
?>
</div>
<div class="example">
<h2>Soft-hyphens</h2>
<h5>&shy; entities</h5>
<?php
$syllable->setHyphen(new \Vanderlee\Syllable\Hyphen\Soft());
echo nl2br($syllable->hyphenateText($source));
?>
</div>
<div class="example">
<h2>Hyphens</h2>
<h5>All hyphen locations</h5>
<?php
$syllable->setHyphen('<span class="debug-hyphen">-</span>');
echo nl2br($syllable->hyphenateText($source));
?>
</div>
<div class="example">
<h2>Zero-width spaces</h2>
<h5>&#8203; entities</h5>
<?php
$syllable->setHyphen(new \Vanderlee\Syllable\Hyphen\ZeroWidthSpace());
echo nl2br($syllable->hyphenateText($source));
?>
</div>
<div class="example">
<h2>Dashes</h2>
<h5>For pre-school reading</h5>
<?php
$syllable->setHyphen(new \Vanderlee\Syllable\Hyphen\Dash());
echo nl2br($syllable->hyphenateText($source));
?>
</div>
</body>
</html>