-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPhonetics.php
58 lines (53 loc) · 1.02 KB
/
Phonetics.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
<?php
/**
* @package go\ewp
*/
namespace go\ewp;
/**
* Phonetics
*
* @author Oleg Grigoriev <go.vasac@gmail.com>
*/
class Phonetics
{
/**
* Constructor
*
* @param string $filename
*/
public function __construct($filename)
{
$s2 = [];
$r2 = [];
$s1 = [];
$r1 = [];
foreach (FileLoader::load($filename) as $k => $v) {
if (\strlen($k) > 1) {
$s2[] = $k;
$r2[] = $v;
} else {
$s1[] = $k;
$r1[] = $v;
}
}
$this->replS = \array_merge($s2, $s1);
$this->replR = \array_merge($r2, $r1);
}
/**
* @param string $content
* @return string
*/
public function __invoke($content)
{
$content = Diacritic::diacritic2latin($content);
return \str_replace($this->replS, $this->replR, $content);
}
/**
* @var array
*/
private $replS;
/**
* @var array
*/
private $replR;
}