This repository was archived by the owner on Aug 2, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCharacters.class.php
More file actions
612 lines (533 loc) · 27.2 KB
/
Characters.class.php
File metadata and controls
612 lines (533 loc) · 27.2 KB
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
<?php
/**
* Character manipulation class
*
* Functions in this class can be used to transliterate characters with
* diacritics to their roman equivalents (romanization) or to convert characters
* to their HTML entities.
*
* LICENSE: CC BY-NC-SA 3.0
* http://creativecommons.org/licenses/by-nc-sa/3.0/
*
*
* @version 1.0
* @author Mihai Zaharie <mihai@zaharie.ro>
* @license http://creativecommons.org/licenses/by-nc-sa/3.0/ CC BY-NC-SA 3.0
*
*
*
* Note: not all the characters in the transliteration map have entities in the
* entities map. More work is required for this.
*/
class Characters
{
/**
* Map of characters and their roman equivalents. Longer characters need to
* be placed before shorter ones.
*
* Based on: http://en.wikipedia.org/wiki/Diacritic#Types
*
*
* Accents
* acute / apex: Áá Ǽǽ Ćć Éé Ǵǵ Íí Ḱḱ Ĺĺ Ḿḿ Ńń Óó Ǿǿ Ṕṕ Ŕŕ Śś Úú Ẃẃ Ýý Źź
* grave: Àà Èè Ìì Ǹǹ Òò Ùù Ẁẁ Ỳỳ
* circumflex: Ââ Ĉĉ Êê Ĝĝ Ĥĥ Îî Ĵĵ Ôô Ŝŝ Ûû Ŵŵ Ŷŷ Ẑẑ
* caron / inverse circumflex: Ǎǎ Čč Ďď Ěě Ǧǧ Ȟȟ Ǐǐ J̌ǰ Ǩǩ Ľľ Ňň Ǒǒ Řř Šš Ťť Ǔǔ Žž Ǯǯ
* double acute: Őő Űű
* double grave: Ȁȁ Ȅȅ Ȉȉ Ȍȍ Ȑȑ Ȕȕ
*
* Dots
* dot above: Ȧȧ Ḃḃ Ċċ Ḋḋ Ėė Ḟḟ Ġġ Ḣḣ İ Ṁṁ Ṅṅ Ȯȯ Ṗṗ Ṙṙ Ṡṡẛ Ṫṫ Ẇẇ Ẋẋ Ẏẏ Żż
* dot below: Ạạ Ḅḅ Ḍḍ Ẹẹ Ḥḥ Ịị Ḳḳ Ḷḷ Ṃṃ Ṇṇ Ọọ Ṛṛ Ṣṣ Ṭṭ Ụụ Ṿṿ Ẉẉ Ỵỵ Ẓẓ
* interpunct
* tittle
* trema / diaeresis / umlaut: Ää Ëë Ḧḧ Ïï N̈n̈ Öö T̈ẗ Üü Ẅẅ Ẍẍ Ÿÿ
* colon
*
* Ring
* ring: Åå Ůů W̊ẘ Y̊ẙ
*
* Vertical line
* vertical line below:
*
* Macron / horizontal line
* macron: Āā Ēē Ḡḡ Īī Ōō Ūū Ȳȳ Ǣǣ
* macron below: Ḇḇ Ḏḏ ẖ Ḵḵ Ḻḻ Ṉṉ Ṟṟ Ṯṯ
*
* Overlays
* bar
* slash
* stroke: Ⱥⱥ Ƀƀ Ȼȼ Đđ Ɇɇ Ǥǥ Ħħ Ɨɨ Ɉɉ Ꝁꝁ Łł Øø Ᵽᵽ Ɍɍ Ŧŧ Ʉʉ Ɏɏ Ƶƶ Ꝥꝥ
*
* Curves
* breve: Ăă Ĕĕ Ğğ Ĭĭ Ŏŏ Ŭŭ
* sicilicus
* tilde: Ãã Ẽẽ Ĩĩ Ññ Õõ P̃p̃ Ũũ Ṽṽ Ỹỹ
* titlo
*
* Curls above
* apostrophe
* hook: Ɓɓ Ƈƈ Ɗɗ Ƒƒ Ɠɠ ɦ Ƙƙ Ɱɱ Ƥƥ ʠ Ƭƭ Ʋʋ Ⱳⱳ Ƴƴ
* horn: Ơơ Ưư
*
* Curls below
* comma: D̦d̦ Șș Țț
* cedilla: Çç Ḑḑ Ȩȩ Ģģ Ḩḩ Ķķ Ļļ Ņņ Ŗŗ Şş Ţţ
* ogonek: Ąą Ą̈ą̈ Ęę Įį Ǫǫ Ǫ̈ǫ̈ Ųų
*
* Double marks
* double breve
* ligature tie
* double circumflex
* double macton
* double tilde
*
* @var array
*/
private static $transliterationMap = array(
"\xC4\x84\xCC\x88" => 'A', "\xC4\x85\xCC\x88" => 'a',
"\xC7\xAA\xCC\x88" => 'O', "\xC7\xAB\xCC\x88" => 'o',
"\xE1\xBA\xA0" => 'A', "\xE1\xBA\xA1" => 'a', "\xE2\xB1\xA5" => 'a',
"\xE1\xB8\x82" => 'B', "\xE1\xB8\x83" => 'b', "\xE1\xB8\x84" => 'B',
"\xE1\xB8\x85" => 'b', "\xE1\xB8\x86" => 'B', "\xE1\xB8\x87" => 'b',
"\xE1\xB8\x8A" => 'D', "\xE1\xB8\x8B" => 'd', "\xE1\xB8\x8C" => 'D',
"\xE1\xB8\x8D" => 'd', "\xE1\xB8\x8E" => 'D', "\xE1\xB8\x8F" => 'd',
"\xE1\xB8\x90" => 'D', "\xE1\xB8\x91" => 'd', "\x44\xCC\xA6" => 'D',
"\x64\xCC\xA6" => 'd',
"\xE1\xBA\xB8" => 'E', "\xE1\xBA\xB9" => 'e', "\xE1\xBA\xB8" => 'E',
"\xE1\xBA\xB9" => 'e', "\xE1\xBA\xBC" => 'E', "\xE1\xBA\xBD" => 'e',
"\xE1\xB8\x9E" => 'F', "\xE1\xB8\x9F" => 'f',
"\xE1\xB8\xA0" => 'G', "\xE1\xB8\xA1" => 'g',
"\xE1\xB8\xA2" => 'H', "\xE1\xB8\xA3" => 'h', "\xE1\xB8\xA4" => 'H',
"\xE1\xB8\xA5" => 'h', "\xE1\xB8\xA6" => 'H', "\xE1\xB8\xA7" => 'h',
"\xE1\xBA\x96" => 'h', "\xE1\xB8\xA8" => 'H', "\xE1\xB8\xA9" => 'h',
"\xE1\xBB\x8A" => 'I', "\xE1\xBB\x8B" => 'i',
"\x4A\xCC\x8C" => 'J',
"\xE1\xB8\xB0" => 'K', "\xE1\xB8\xB1" => 'k', "\xE1\xB8\xB2" => 'K',
"\xE1\xB8\xB3" => 'k', "\xE1\xB8\xB4" => 'K', "\xE1\xB8\xB5" => 'k',
"\xEA\x9D\x80" => 'K', "\xEA\x9D\x81" => 'k',
"\xE1\xB8\xB6" => 'L', "\xE1\xB8\xB7" => 'l', "\xE1\xB8\xBA" => 'L',
"\xE1\xB8\xBB" => 'l',
"\xE1\xB8\xBE" => 'M', "\xE1\xB8\xBF" => 'm', "\xE1\xB9\x80" => 'M',
"\xE1\xB9\x81" => 'm', "\xE1\xB9\x82" => 'M', "\xE1\xB9\x83" => 'm',
"\xE2\xB1\xAE" => 'M',
"\xE1\xB9\x84" => 'N', "\xE1\xB9\x85" => 'n', "\xE1\xB9\x86" => 'N',
"\xE1\xB9\x87" => 'n', "\x4E\xCC\x88" => 'N', "\x6E\xCC\x88" => 'n',
"\xE1\xB9\x88" => 'N', "\xE1\xB9\x89" => 'n',
"\xE1\xBB\x8C" => 'O', "\xE1\xBB\x8D" => 'o',
"\xE1\xB9\x94" => 'P', "\xE1\xB9\x95" => 'p', "\xE1\xB9\x96" => 'P',
"\xE1\xB9\x97" => 'p', "\xE2\xB1\xA3" => 'P', "\xE1\xB5\xBD" => 'p',
"\x50\xCC\x83" => 'P', "\x70\xCC\x83" => 'p',
"\xE1\xB9\x98" => 'R', "\xE1\xB9\x99" => 'r', "\xE1\xB9\x9A" => 'R',
"\xE1\xB9\x9B" => 'r', "\xE1\xB9\x9E" => 'R', "\xE1\xB9\x9F" => 'r',
"\xE1\xB9\xA0" => 'S', "\xE1\xB9\xA1" => 's', "\xE1\xBA\x9B" => 's',
"\xE1\xB9\xA2" => 'S', "\xE1\xB9\xA3" => 's',
"\xE1\xB9\xAA" => 'T', "\xE1\xB9\xAB" => 't', "\xE1\xB9\xAC" => 'T',
"\xE1\xB9\xAD" => 't', "\x54\xCC\x88" => 'T', "\xE1\xBA\x97" => 't',
"\xE1\xB9\xAE" => 'T', "\xE1\xB9\xAF" => 't',
"\xEA\x9D\xA4" => 'Th', "\xEA\x9D\xA5" => 'th',
"\xE1\xBB\xA4" => 'U', "\xE1\xBB\xA5" => 'u',
"\xE1\xB9\xBE" => 'V', "\xE1\xB9\xBF" => 'v', "\xE1\xB9\xBC" => 'V',
"\xE1\xB9\xBD" => 'v',
"\xE1\xBA\x82" => 'W', "\xE1\xBA\x83" => 'w', "\xE1\xBA\x80" => 'W',
"\xE1\xBA\x81" => 'w', "\xE1\xBA\x86" => 'W', "\xE1\xBA\x87" => 'w',
"\xE1\xBA\x88" => 'W', "\xE1\xBA\x89" => 'w', "\xE1\xBA\x84" => 'W',
"\xE1\xBA\x85" => 'w', "\x57\xCC\x8A" => 'W', "\xE1\xBA\x98" => 'w',
"\xE2\xB1\xB2" => 'W', "\xE2\xB1\xB3" => 'w',
"\xE1\xBA\x8A" => 'X', "\xE1\xBA\x8B" => 'x', "\xE1\xBA\x8C" => 'X',
"\xE1\xBA\x8D" => 'x',
"\xE1\xBB\xB2" => 'Y', "\xE1\xBB\xB3" => 'y', "\xE1\xBA\x8E" => 'Y',
"\xE1\xBA\x8F" => 'y', "\xE1\xBB\xB4" => 'Y', "\xE1\xBB\xB5" => 'y',
"\x59\xCC\x8A" => 'Y', "\xE1\xBA\x99" => 'y', "\xE1\xBB\xB8" => 'Y',
"\xE1\xBB\xB9" => 'y',
"\xE1\xBA\x90" => 'Z', "\xE1\xBA\x91" => 'z', "\xE1\xBA\x92" => 'Z',
"\xE1\xBA\x93" => 'z',
"\xC3\x81" => 'A', "\xC3\xA1" => 'a', "\xC3\x80" => 'A', "\xC3\xA0" => 'a',
"\xC3\x82" => 'A', "\xC3\xA2" => 'a', "\xC7\x8D" => 'A', "\xC7\x8E" => 'a',
"\xC8\x80" => 'A', "\xC8\x81" => 'a', "\xC8\xA6" => 'A', "\xC8\xA7" => 'a',
"\xC3\x84" => 'A', "\xC3\xA4" => 'a', "\xC3\x85" => 'A', "\xC3\xA5" => 'a',
"\xC4\x80" => 'A', "\xC4\x81" => 'a', "\xC8\xBA" => 'A', "\xC4\x82" => 'A',
"\xC4\x83" => 'a', "\xC3\x83" => 'A', "\xC3\xA3" => 'a', "\xC4\x84" => 'A',
"\xC4\x85" => 'a',
"\xC7\xBC" => 'Ae', "\xC7\xBD" => 'ae', "\xC7\xA2" => 'Ae', "\xC7\xA3" => 'ae',
"\xC9\x83" => 'B', "\xC6\x80" => 'b', "\xC6\x81" => 'B', "\xC9\x93" => 'b',
"\xC4\x86" => 'C', "\xC4\x87" => 'c', "\xC4\x88" => 'C', "\xC4\x89" => 'c',
"\xC4\x8C" => 'C', "\xC4\x8D" => 'c', "\xC4\x8A" => 'C', "\xC4\x8B" => 'c',
"\xC8\xBB" => 'C', "\xC8\xBC" => 'c', "\xC6\x87" => 'C', "\xC6\x88" => 'c',
"\xC3\x87" => 'C', "\xC3\xA7" => 'c',
"\xC4\x8E" => 'D', "\xC4\x8F" => 'd', "\xC4\x90" => 'D', "\xC4\x91" => 'd',
"\xC6\x8A" => 'D', "\xC9\x97" => 'd', "\xC3\x90" => 'D', "\xC3\xB0" => 'd',
"\xC3\x89" => 'E', "\xC3\xA9" => 'e', "\xC3\x88" => 'E', "\xC3\xA8" => 'e',
"\xC3\x8A" => 'E', "\xC3\xAA" => 'e', "\xC4\x9A" => 'E', "\xC4\x9B" => 'e',
"\xC8\x84" => 'E', "\xC8\x85" => 'e', "\xC4\x96" => 'E', "\xC4\x97" => 'e',
"\xC3\x8B" => 'E', "\xC3\xAB" => 'e', "\xC4\x92" => 'E', "\xC4\x93" => 'e',
"\xC9\x86" => 'E', "\xC9\x87" => 'e', "\xC4\x94" => 'E', "\xC4\x95" => 'e',
"\xC8\xA8" => 'E', "\xC8\xA9" => 'e', "\xC4\x98" => 'E', "\xC4\x99" => 'e',
"\xC6\x91" => 'F', "\xC6\x92" => 'f',
"\xC7\xB4" => 'G', "\xC7\xB5" => 'g', "\xC4\x9C" => 'G', "\xC4\x9D" => 'g',
"\xC7\xA6" => 'G', "\xC7\xA7" => 'g', "\xC4\xA0" => 'G', "\xC4\xA1" => 'g',
"\xC7\xA4" => 'G', "\xC7\xA5" => 'g', "\xC4\x9E" => 'G', "\xC4\x9F" => 'g',
"\xC6\x93" => 'G', "\xC9\xA0" => 'g', "\xC4\xA2" => 'G', "\xC4\xA3" => 'g',
"\xC4\xA4" => 'H', "\xC4\xA5" => 'h', "\xC8\x9E" => 'H', "\xC8\x9F" => 'h',
"\xC4\xA6" => 'H', "\xC4\xA7" => 'h', "\xC9\xA6" => 'h',
"\xC3\x8D" => 'I', "\xC3\xAD" => 'i', "\xC3\x8C" => 'I', "\xC3\xAC" => 'i',
"\xC3\x8E" => 'I', "\xC3\xAE" => 'i', "\xC7\x8F" => 'I', "\xC7\x90" => 'i',
"\xC8\x88" => 'I', "\xC8\x89" => 'i', "\xC4\xB0" => 'I', "\xC3\x8F" => 'I',
"\xC3\xAF" => 'i', "\xC4\xAA" => 'I', "\xC4\xAB" => 'i', "\xC6\x97" => 'I',
"\xC9\xA8" => 'i', "\xC4\xAC" => 'I', "\xC4\xAD" => 'i', "\xC4\xA8" => 'I',
"\xC4\xA9" => 'i', "\xC4\xAE" => 'I', "\xC4\xAF" => 'i',
"\xC4\xB4" => 'J', "\xC4\xB5" => 'j', "\xC7\xB0" => 'j', "\xC9\x88" => 'J',
"\xC9\x89" => 'j',
"\xC7\xA8" => 'K', "\xC7\xA9" => 'k', "\xC6\x98" => 'K', "\xC6\x99" => 'k',
"\xC4\xB6" => 'K', "\xC4\xB7" => 'k',
"\xC4\xB9" => 'L', "\xC4\xBA" => 'l', "\xC4\xBD" => 'L', "\xC4\xBE" => 'l',
"\xC5\x81" => 'L', "\xC5\x82" => 'l', "\xC4\xBB" => 'L', "\xC4\xBC" => 'l',
"\xC9\xB1" => 'm',
"\xC5\x83" => 'N', "\xC5\x84" => 'n', "\xC7\xB8" => 'N', "\xC7\xB9" => 'n',
"\xC5\x87" => 'N', "\xC5\x88" => 'n', "\xC3\x91" => 'N', "\xC3\xB1" => 'n',
"\xC5\x85" => 'N', "\xC5\x86" => 'n',
"\xC3\x93" => 'O', "\xC3\xB3" => 'o', "\xC7\xBE" => 'O', "\xC7\xBF" => 'o',
"\xC3\x92" => 'O', "\xC3\xB2" => 'o', "\xC3\x94" => 'O', "\xC3\xB4" => 'o',
"\xC7\x91" => 'O', "\xC7\x92" => 'o', "\xC5\x90" => 'O', "\xC5\x91" => 'o',
"\xC8\x8C" => 'O', "\xC8\x8D" => 'o', "\xC8\xAE" => 'O', "\xC8\xAF" => 'o',
"\xC3\x96" => 'O', "\xC3\xB6" => 'o', "\xC5\x8C" => 'O', "\xC5\x8D" => 'o',
"\xC3\x98" => 'O', "\xC3\xB8" => 'o', "\xC5\x8E" => 'O', "\xC5\x8F" => 'o',
"\xC3\x95" => 'O', "\xC3\xB5" => 'o', "\xC6\xA0" => 'O', "\xC6\xA1" => 'o',
"\xC7\xAA" => 'O', "\xC7\xAB" => 'o',
"\xC6\xA4" => 'P', "\xC6\xA5" => 'p',
"\xCA\xA0" => 'q',
"\xC5\x94" => 'R', "\xC5\x95" => 'r', "\xC5\x98" => 'R', "\xC5\x99" => 'r',
"\xC8\x90" => 'R', "\xC8\x91" => 'r', "\xC9\x8C" => 'R', "\xC9\x8D" => 'r',
"\xC5\x96" => 'R', "\xC5\x97" => 'r',
"\xC5\x9A" => 'S', "\xC5\x9B" => 's', "\xC5\x9C" => 'S', "\xC5\x9D" => 's',
"\xC5\x9E" => 'S', "\xC5\x9F" => 's', "\xC8\x98" => 'S', "\xC8\x99" => 's',
"\xC5\xA0" => 'S', "\xC5\xA1" => 's',
"\xC5\xA4" => 'T', "\xC5\xA5" => 't', "\xC5\xA6" => 'T', "\xC5\xA7" => 't',
"\xC6\xAC" => 'T', "\xC6\xAD" => 't', "\xC5\xA2" => 'T', "\xC5\xA3" => 't',
"\xC8\x9A" => 'T', "\xC8\x9B" => 't',
"\xC3\x9A" => 'U', "\xC3\xBA" => 'u', "\xC3\x99" => 'U', "\xC3\xB9" => 'u',
"\xC3\x9B" => 'U', "\xC3\xBB" => 'u', "\xC7\x93" => 'U', "\xC7\x94" => 'u',
"\xC5\xB0" => 'U', "\xC5\xB1" => 'u', "\xC8\x94" => 'U', "\xC8\x95" => 'u',
"\xC3\x9C" => 'U', "\xC3\xBC" => 'u', "\xC5\xAE" => 'U', "\xC5\xAF" => 'u',
"\xC5\xAA" => 'U', "\xC5\xAB" => 'u',
"\xC9\x84" => 'U', "\xCA\x89" => 'u', "\xC5\xAC" => 'U', "\xC5\xAD" => 'u',
"\xC5\xA8" => 'U', "\xC5\xA9" => 'u', "\xC6\xB2" => 'U', "\xCA\x8B" => 'u',
"\xC6\xAF" => 'U', "\xC6\xB0" => 'u', "\xC5\xB2" => 'U', "\xC5\xB3" => 'u',
"\xC5\xB4" => 'W', "\xC5\xB5" => 'w',
"\xC3\x9D" => 'Y', "\xC3\xBD" => 'y', "\xC5\xB6" => 'Y', "\xC5\xB7" => 'y',
"\xC5\xB8" => 'Y', "\xC3\xBF" => 'y', "\xC8\xB2" => 'Y', "\xC8\xB3" => 'y',
"\xC9\x8E" => 'Y', "\xC9\x8F" => 'y', "\xC6\xB3" => 'Y', "\xC6\xB4" => 'y',
"\xC5\xB9" => 'Z', "\xC5\xBA" => 'z', "\xC5\xBD" => 'Z', "\xC5\xBE" => 'z',
"\xC7\xAE" => 'Z', "\xC7\xAF" => 'z', "\xC5\xBB" => 'Z', "\xC5\xBC" => 'z',
"\xC6\xB5" => 'Z', "\xC6\xB6" => 'z'
);
/**
* Map of characters and their roman equivalents. Longer characters need to
* be placed before shorter ones.
*
* @var array
*/
private static $symbolsTransliterationMap = array(
// Punctuation
"\xC2\xAB" => '<<', "\xC2\xBB" => '>>',
"\xE2\x9F\xA8" => '<', "\xE2\x9F\xA9" => '>', "\xE2\x80\x92" => '-',
"\xE2\x80\x93" => '-', "\xE2\x80\x94" => '-', "\xE2\x80\x95" => '-',
"\xE2\x80\xA6" => '...', "\xE2\x80\x90" => '-', "\xE2\x80\x98" => "'",
"\xE2\x80\x99" => "'", "\xE2\x80\x9A" => "'", "\xE2\x80\x9C" => '"',
"\xE2\x80\x9D" => '"', "\xE2\x80\x9E" => '"', "\xE2\x81\x84" => '/',
// Word dividers
"\xC2\xB7" => ' ',
"\xE2\x80\x82" => ' ', "\xE2\x80\x83" => ' ', "\xE2\x80\x89" => ' ',
"\xE2\x90\xA0" => ' ', "\xE2\x90\xA2" => ' ', "\xE2\x90\xA3" => '_',
// General typography
"\xC2\xA9" => '(c)', "\xC2\xAE" => '(r)', "\xC2\xA1" => '!',
"\xC2\xBF" => '?', "\xC2\xA6" => '|',
"\xE2\x80\xA2" => '*', "\xE3\x80\x83" => '"', "\xE2\x84\x96" => 'No.',
"\xE2\x80\xB2" => "'", "\xE2\x80\xB3" => '"', "\xE2\x80\xB4" => '"\'',
"\xE2\x84\xA0" => 'sm', "\xE2\x84\x97" => '(p)', "\xE2\x84\xA2" => 'tm',
// Currency
"\xC2\xA2" => 'c', "\xC2\xA3" => 'GBP', "\xC2\xA5" => 'JPY',
"\xC6\x92" => 'f', "\x24" => 'USD',
"\xE2\x82\xB3" => 'ARA', "\xE0\xB8\xBF" => 'THB', "\xE2\x82\xB5" => 'GHS',
"\xE2\x82\xA1" => 'CRC', "\xE2\x82\xA2" => 'BRZ', "\xE2\x82\xA0" => 'ECU',
"\xE2\x82\xAB" => 'VND', "\xE0\xA7\xB3" => 'BDT', "\xE2\x82\xAF" => 'GRD',
"\xE2\x82\xAC" => 'EUR', "\xE2\x82\xA3" => 'FRF', "\xE2\x82\xB2" => 'PYG',
"\xE2\x82\xB4" => 'UAH', "\xE2\x82\xAD" => 'LAK', "\xE2\x84\xB3" => 'GGK',
"\xE2\x82\xA5" => 'mil', "\xE2\x82\xA6" => 'NGN', "\xE2\x82\xA7" => 'ESP',
"\xE2\x82\xB1" => 'PHP', "\xE2\x82\xB0" => 'Pf', "\xE2\x82\xB9" => 'INR',
"\xE2\x82\xA8" => 'Rs', "\xE2\x82\xAA" => 'ILS', "\xE2\x82\xB8" => 'ZKT',
"\xE2\x82\xAE" => 'MNT', "\xE2\x82\xA9" => 'KRW', "\xE1\x9F\x9B" => 'KHR',
// Uncommon typography
"\xE2\x80\xBD" => '!?', "\xE2\x81\x80" => '_',
// Mathematic symbols
"\xC2\xB9" => '1', "\xC2\xB2" => '2', "\xC2\xB3" => '3',
"\xC2\xBC" => '1/4', "\xC2\xBD" => '1/2', "\xC2\xBE" => '3/4',
"\xC2\xB1" => '+-', "\xC2\xB5" => 'u', "\xC3\x97" => '*',
"\xE2\x84\x91" => 'I', "\xE2\x84\x98" => 'P', "\xE2\x84\x9C" => 'R',
// Ligatures
"\xC3\x86" => 'Ae', "\xC3\xA6" => 'ae', "\xC5\x92" => 'Oe',
"\xC5\x93" => 'oe', "\xC3\x9F" => 'ss', "\xC3\x9E" => 'Th',
"\xC3\xBE" => 'th',
"\xE1\xBA\x9E" => 'Ss',
// Greek letters
"\xCE\x91" => 'A', "\xCE\x92" => 'B', "\xCE\x93" => 'G', "\xCE\x94" => 'D',
"\xCE\x95" => 'E', "\xCE\x96" => 'Z', "\xCE\x97" => 'H', "\xCE\x98" => 'Th',
"\xCE\x99" => 'I', "\xCE\x9A" => 'K', "\xCE\x9B" => 'L', "\xCE\x9C" => 'M',
"\xCE\x9D" => 'N', "\xCE\x9E" => 'X', "\xCE\x9F" => 'O', "\xCE\xA0" => 'P',
"\xCE\xA1" => 'R', "\xCE\xA3" => 'S', "\xCE\xA4" => 'T', "\xCE\xA5" => 'Y',
"\xCE\xA6" => 'Ph', "\xCE\xA7" => 'Ch', "\xCE\xA8" => 'Ps', "\xCE\xA9" => 'O',
"\xCE\xB1" => 'a', "\xCE\xB2" => 'b', "\xCE\xB3" => 'g', "\xCE\xB4" => 'd',
"\xCE\xB5" => 'e', "\xCE\xB6" => 'z', "\xCE\xB7" => 'h', "\xCE\xB8" => 'th',
"\xCE\xB9" => 'i', "\xCE\xBA" => 'k', "\xCE\xBB" => 'l', "\xCE\xBC" => 'm',
"\xCE\xBD" => 'n', "\xCE\xBE" => 'x', "\xCE\xBF" => 'o', "\xCF\x80" => 'p',
"\xCF\x81" => 'r', "\xCF\x82" => 's', "\xCF\x83" => 's', "\xCF\x84" => 't',
"\xCF\x85" => 'u', "\xCF\x86" => 'ph', "\xCF\x87" => 'ch', "\xCF\x88" => 'ps',
"\xCF\x89" => 'o', "\xCF\x91" => 'th', "\xCF\x92" => 'y', "\xCF\x96" => 'p'
);
/**
* Map of characters entities and the actual characters.
*
* Based on: http://en.wikipedia.org/wiki/Punctuation and
* http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references
*
* @var array
*/
private static $entitiesMap = array(
// Romanian characters
"\xC4\x82" => 'Ă', "\xC4\x83" => 'ă', "\xC3\x82" => 'Â',
"\xC3\xA2" => 'â', "\xC3\x8E" => 'Î', "\xC3\xAE" => 'î',
"\xC8\x98" => 'Ș', "\xC8\x99" => 'ș', "\xC5\x9E" => 'Ş',
"\xC5\x9F" => 'ş', "\xC8\x9A" => 'Ț', "\xC8\x9B" => 'ț',
"\xC5\xA2" => 'Ţ', "\xC5\xA3" => 'ţ',
// Punctuation
"\x27" => ''', // apostrophe
"\x22" => '"', // double quotation mark
"\xC2\xAB" => '«', "\xC2\xBB" => '»', // guillemets
"\xE2\x9F\xA8" => '⟨', "\xE2\x9F\xA9" => '⟩', // brakets
"\xE2\x80\x92" => '‒', "\xE2\x80\x93" => '–', "\xE2\x80\x94" => '—', "\xE2\x80\x95" => '―', // dash
"\xE2\x80\xA6" => '…', // ellipsis
"\xE2\x80\x90" => '‐', // hyphen
"\xE2\x80\x98" => '‘', "\xE2\x80\x99" => '’', "\xE2\x80\x9A" => '‚', // single quotation marks
"\xE2\x80\x9C" => '“', "\xE2\x80\x9D" => '”', "\xE2\x80\x9E" => '„', // double quotation marks
"\xE2\x81\x84" => '⁄', // solidus
// Word dividers
"\xC2\xB7" => '·', // interpunct
"\xE2\x80\x82" => ' ', "\xE2\x80\x83" => ' ', "\xE2\x80\x89" => ' ', "\xE2\x90\xA0" => '␠', "\xE2\x90\xA2" => '␢', "\xE2\x90\xA3" => '␣', // space
// General typography
// "\x26" => '&', // ampersand
"\xC2\xA9" => '©', // copyright symbol
"\xC2\xB0" => '°', // degree
"\xC2\xA1" => '¡', // inverted exclamation mark
"\xC2\xBF" => '¿', // inverted question mark
"\xC3\xB7" => '÷', // obelus
"\xC2\xBA" => 'º', "\xC2\xAA" => 'ª', // ordinal indicator
"\xC2\xB6" => '¶', // pilcrow
"\xC2\xAE" => '®', // registered trademark
"\xC2\xA7" => '§', // section sign
"\xC2\xA6" => '¦', // vertical broken bar
"\xE2\x80\xA2" => '•', // bullet
"\xE2\x80\xA0" => '†', "\xE2\x80\xA1" => '‡', // dagger
"\xE3\x80\x83" => '〃', // ditto mark
"\xE2\x84\x96" => '№', // numero sign
"\xE2\x80\xB0" => '‰', "\xE2\x80\xB1" => '‱', // percent
"\xE2\x80\xB2" => '′', "\xE2\x80\xB3" => '″', "\xE2\x80\xB4" => '‴', // prime
"\xE2\x84\xA0" => '℠', // service mark
"\xE2\x84\x97" => '℗', // sound recording copyright
"\xE2\x84\xA2" => '™', // trademark
// Currency
"\xC2\xA4" => '¤', // currency (generic)
"\xC2\xA2" => '¢', "\xC2\xA3" => '£', "\xC2\xA5" => '¥',
"\xC6\x92" => 'ƒ',
"\xE2\x82\xB3" => '₳', "\xE0\xB8\xBF" => '฿', "\xE2\x82\xB5" => '₵',
"\xE2\x82\xA1" => '₡', "\xE2\x82\xA2" => '₢', "\xE2\x82\xA0" => '₠',
"\xE2\x82\xAB" => '₫', "\xE0\xA7\xB3" => '৳', "\xE2\x82\xAF" => '₯',
"\xE2\x82\xAC" => '€', "\xE2\x82\xA3" => '₣', "\xE2\x82\xB2" => '₲',
"\xE2\x82\xB4" => '₴', "\xE2\x82\xAD" => '₭', "\xE2\x84\xB3" => 'ℳ',
"\xE2\x82\xA5" => '₥', "\xE2\x82\xA6" => '₦', "\xE2\x82\xA7" => '₧',
"\xE2\x82\xB1" => '₱', "\xE2\x82\xB0" => '₰', "\xE2\x82\xB9" => '₹',
"\xE2\x82\xA8" => '₨', "\xE2\x82\xAA" => '₪', "\xE2\x82\xB8" => '₸',
"\xE2\x82\xAE" => '₮', "\xE2\x82\xA9" => '₩', "\xE1\x9F\x9B" => '៛',
// Uncommon typography
"\xE2\x81\x82" => '⁂', // asterism
"\xE2\x8A\xA4" => '⊤', // tee
"\xE2\x98\x9E" => '☞', // index/fist
"\xE2\x80\xBD" => '‽', // interrobang
"\xE2\xB8\xAE" => '⸮', // irony & sarcasm punctuation
"\xE2\x80\xBB" => '※', // reference mark
"\xE2\x81\x80" => '⁀', // tie
// Mathematic symbols
"\x3C" => '<', "\x3E" => '>', // less-than, greater-than
"\xC2\xB9" => '¹', // superscript one
"\xC2\xB2" => '²', // superscript two
"\xC2\xB3" => '³', // superscript three
"\xC2\xBC" => '¼', // vulgar fraction one quarter
"\xC2\xBD" => '½', // vulgar fraction one half
"\xC2\xBE" => '¾', // vulgar fraction three quarters
"\xC2\xAC" => '¬', // not sign
"\xC2\xB1" => '±', // plus-minus sign
"\xC2\xB5" => 'µ', // micro sign
"\xC3\x97" => '×', // multiplication sign
"\xE2\x84\x91" => 'ℑ', // black-letter capital I (= imaginary part)
"\xE2\x84\x98" => '℘', // script capital P (= power set = Weierstrass p)
"\xE2\x84\x9C" => 'ℜ', // black-letter capital R (= real part symbol)
"\xE2\x84\xB5" => 'ℵ', // alef symbol (= first transfinite cardinal)
"\xE2\x86\x90" => '←', // leftwards arrow
"\xE2\x86\x91" => '↑', // upwards arrow
"\xE2\x86\x92" => '→', // rightwards arrow
"\xE2\x86\x93" => '↓', // downwards arrow
"\xE2\x86\x94" => '↔', // left right arrow
"\xE2\x86\xB5" => '↵', // downwards arrow with corner leftwards (= carriage return)
"\xE2\x87\x90" => '⇐', // leftwards double arrow
"\xE2\x87\x91" => '⇑', // upwards double arrow
"\xE2\x87\x92" => '⇒', // rightwards double arrow
"\xE2\x87\x93" => '⇓', // downwards double arrow
"\xE2\x87\x94" => '⇔', // left right double arrow
"\xE2\x88\x80" => '∀', // for all
"\xE2\x88\x82" => '∂', // partial differential
"\xE2\x88\x83" => '∃', // there exists
"\xE2\x88\x85" => '∅', // empty set (= null set = diameter)
"\xE2\x88\x87" => '∇', // nabla (= backward difference)
"\xE2\x88\x88" => '∈', // element of
"\xE2\x88\x89" => '∉', // not an element of
"\xE2\x88\x8B" => '∋', // contains as member
"\xE2\x88\x8F" => '∏', // n-ary product (= product sign)
"\xE2\x88\x91" => '∑', // n-ary summation
"\xE2\x88\x92" => '−', // minus sign
"\xE2\x88\x97" => '∗', // asterisk operator
"\xE2\x88\x9A" => '√', // square root (= radical sign)
"\xE2\x88\x9D" => '∝', // proportional to
"\xE2\x88\x9E" => '∞', // infinity
"\xE2\x88\xA0" => '∠', // angle
"\xE2\x88\xA7" => '∧', // logical and (= wedge)
"\xE2\x88\xA8" => '∨', // logical or (= vee)
"\xE2\x88\xA9" => '∩', // intersection (= cap)
"\xE2\x88\xAA" => '∪', // union (= cup)
"\xE2\x88\xAB" => '∫', // integral
"\xE2\x88\xB4" => '∴', // therefore sign
"\xE2\x88\xB5" => '∵', // because sign
"\xE2\x88\xBC" => '∼', // tilde operator (= varies with = similar to)
"\xE2\x89\x85" => '≅', // congruent to
"\xE2\x89\x88" => '≈', // almost equal to (= asymptotic to)
"\xE2\x89\xA0" => '≠', // not equal to
"\xE2\x89\xA1" => '≡', // identical to; sometimes used for 'equivalent to'
"\xE2\x89\xA4" => '≤', // less-than or equal to
"\xE2\x89\xA5" => '≥', // greater-than or equal to
"\xE2\x8A\x82" => '⊂', // subset of
"\xE2\x8A\x83" => '⊃', // superset of
"\xE2\x8A\x84" => '⊄', // not a subset of
"\xE2\x8A\x86" => '⊆', // subset of or equal to
"\xE2\x8A\x87" => '⊇', // superset of or equal to
"\xE2\x8A\x95" => '⊕', // circled plus (= direct sum)
"\xE2\x8A\x97" => '⊗', // circled times (= vector product)
"\xE2\x8A\xA5" => '⊥', // up tack (= orthogonal to = perpendicular)
"\xE2\x8B\x85" => '⋅', // dot operator
"\xE2\x8C\x88" => '⌈', // left ceiling (= APL upstile)
"\xE2\x8C\x89" => '⌉', // right ceiling
"\xE2\x8C\x8A" => '⌊', // left floor (= APL downstile)
"\xE2\x8C\x8B" => '⌋', // right floor
"\xE3\x80\x88" => '⟨', // left-pointing angle bracket (= bra)
"\xE3\x80\x89" => '⟩', // right-pointing angle bracket (= ket)
"\xE2\x97\x8A" => '◊', // lozenge
// Accents
"\xC2\xA8" => '¨', // diaeresis
"\xC2\xAF" => '¯', // macron
"\xC2\xB4" => '´', // acute accent
"\xC2\xB8" => '¸', // cedilla
"\xCB\x86" => 'ˆ', // circumflex accent
"\xE2\x80\xBE" => '‾', // overline
// Accented letters
"\xC3\x80" => 'À', "\xC3\x81" => 'Á', "\xC3\x83" => 'Ã',
"\xC3\x84" => 'Ä', "\xC3\x85" => 'Å', "\xC3\x86" => 'Æ',
"\xC3\x87" => 'Ç', "\xC3\x88" => 'È', "\xC3\x89" => 'É',
"\xC3\x8A" => 'Ê', "\xC3\x8B" => 'Ë', "\xC3\x8C" => 'Ì',
"\xC3\x8D" => 'Í', "\xC3\x8F" => 'Ï', "\xC3\x90" => 'Ð',
"\xC3\x91" => 'Ñ', "\xC3\x92" => 'Ò', "\xC3\x93" => 'Ó',
"\xC3\x94" => 'Ô', "\xC3\x95" => 'Õ', "\xC3\x96" => 'Ö',
"\xC3\x98" => 'Ø', "\xC3\x99" => 'Ù', "\xC3\x9A" => 'Ú',
"\xC3\x9B" => 'Û', "\xC3\x9C" => 'Ü', "\xC3\x9D" => 'Ý',
"\xC3\x9E" => 'Þ', "\xC3\x9F" => 'ß', "\xC3\xA0" => 'à',
"\xC3\xA1" => 'á', "\xC3\xA3" => 'ã', "\xC3\xA4" => 'ä',
"\xC3\xA5" => 'å', "\xC3\xA6" => 'æ', "\xC3\xA7" => 'ç',
"\xC3\xA8" => 'è', "\xC3\xA9" => 'é', "\xC3\xAA" => 'ê',
"\xC3\xAB" => 'ë', "\xC3\xAC" => 'ì', "\xC3\xAD" => 'í',
"\xC3\xAF" => 'ï', "\xC3\xB0" => 'ð', "\xC3\xB1" => 'ñ',
"\xC3\xB2" => 'ò', "\xC3\xB3" => 'ó', "\xC3\xB4" => 'ô',
"\xC3\xB5" => 'õ', "\xC3\xB6" => 'ö', "\xC3\xB8" => 'ø',
"\xC3\xB9" => 'ù', "\xC3\xBA" => 'ú', "\xC3\xBB" => 'û',
"\xC3\xBC" => 'ü', "\xC3\xBD" => 'ý', "\xC3\xBE" => 'þ',
"\xC3\xBF" => 'ÿ', "\xC5\x92" => 'Œ', "\xC5\x93" => 'œ',
"\xC5\xA0" => 'Š', "\xC5\xA1" => 'š', "\xC5\xB8" => 'Ÿ',
"\xE1\xBA\x9E" => 'ẞ',
// Greek letters
"\xCE\x91" => 'Α', "\xCE\x92" => 'Β', "\xCE\x93" => 'Γ',
"\xCE\x94" => 'Δ', "\xCE\x95" => 'Ε', "\xCE\x96" => 'Ζ',
"\xCE\x97" => 'Η', "\xCE\x98" => 'Θ', "\xCE\x99" => 'Ι',
"\xCE\x9A" => 'Κ', "\xCE\x9B" => 'Λ', "\xCE\x9C" => 'Μ',
"\xCE\x9D" => 'Ν', "\xCE\x9E" => 'Ξ', "\xCE\x9F" => 'Ο',
"\xCE\xA0" => 'Π', "\xCE\xA1" => 'Ρ', "\xCE\xA3" => 'Σ',
"\xCE\xA4" => 'Τ', "\xCE\xA5" => 'Υ', "\xCE\xA6" => 'Φ',
"\xCE\xA7" => 'Χ', "\xCE\xA8" => 'Ψ', "\xCE\xA9" => 'Ω',
"\xCE\xB1" => 'α', "\xCE\xB2" => 'β', "\xCE\xB3" => 'γ',
"\xCE\xB4" => 'δ', "\xCE\xB5" => 'ε', "\xCE\xB6" => 'ζ',
"\xCE\xB7" => 'η', "\xCE\xB8" => 'θ', "\xCE\xB9" => 'ι',
"\xCE\xBA" => 'κ', "\xCE\xBB" => 'λ', "\xCE\xBC" => 'μ',
"\xCE\xBD" => 'ν', "\xCE\xBE" => 'ξ', "\xCE\xBF" => 'ο',
"\xCF\x80" => 'π', "\xCF\x81" => 'ρ', "\xCF\x82" => 'ς',
"\xCF\x83" => 'σ', "\xCF\x84" => 'τ', "\xCF\x85" => 'υ',
"\xCF\x86" => 'φ', "\xCF\x87" => 'χ', "\xCF\x88" => 'ψ',
"\xCF\x89" => 'ω', "\xCF\x91" => 'ϑ', "\xCF\x92" => 'ϒ',
"\xCF\x96" => 'ϖ',
// Other
"\xE2\x99\xA0" => '♠', // black spade suit
"\xE2\x99\xA3" => '♣', // black club suit (= shamrock)
"\xE2\x99\xA5" => '♥', // black heart suit (= valentine)
"\xE2\x99\xA6" => '♦', // black diamond suit
);
/**
* Transforms the characters according to the map.
*
* @param array $map
* @param string $text
*
* @return string
*/
private static function mapTransform($text, $map)
{
// return strtr($text, $map);
return str_replace(array_keys($map), array_values($map), $text);
}
/**
* Replaces characters with diacritics with their roman equivalents.
*
* @param string $text Input text
* @param bool $withSymbols "Transliterate" symbols too
* @param bool $removeNonASCII Remove non ASCII characters
*
* @return string
*/
public static function diacritics($text, $withSymbols = false, $removeNonASCII = false)
{
$transformed = $text;
if ($withSymbols)
{
$transformed = self::mapTransform($transformed, self::$symbolsTransliterationMap);
}
$transformed = self::mapTransform($transformed, self::$transliterationMap);
if ($removeNonASCII)
{
$transformed = preg_replace('/[^(\x20-\x7F)\x0A]*/','', $transformed);
}
return $transformed;
}
/**
* Replaces characters with their HTML entities.
*
* @param string $text Input text
*
* @return string
*/
public static function entities($text)
{
return self::mapTransform($text, self::$entitiesMap);
}
}