|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Created by rozbo at 2017/3/18 下午9:03 |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
namespace puck\tools; |
|
7
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
class Str { |
|
10
|
|
|
/** |
|
11
|
|
|
* The cache of snake-cased words. |
|
12
|
|
|
* |
|
13
|
|
|
* @var array |
|
14
|
|
|
*/ |
|
15
|
|
|
protected static $snakeCache = []; |
|
16
|
|
|
/** |
|
17
|
|
|
* The cache of camel-cased words. |
|
18
|
|
|
* |
|
19
|
|
|
* @var array |
|
20
|
|
|
*/ |
|
21
|
|
|
protected static $camelCache = []; |
|
22
|
|
|
/** |
|
23
|
|
|
* The cache of studly-cased words. |
|
24
|
|
|
* |
|
25
|
|
|
* @var array |
|
26
|
|
|
*/ |
|
27
|
|
|
protected static $studlyCache = []; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* 判断一个字符串是否以给定字符串开始 |
|
31
|
|
|
* |
|
32
|
|
|
* @param string $haystack |
|
33
|
|
|
* @param string|array $needles |
|
34
|
|
|
* @return bool |
|
35
|
|
|
*/ |
|
36
|
3 |
|
public static function startsWith($haystack, $needles) |
|
37
|
|
|
{ |
|
38
|
3 |
|
foreach ((array) $needles as $needle) { |
|
39
|
3 |
|
if ($needle != '' && substr($haystack, 0, strlen($needle)) === (string) $needle) { |
|
40
|
3 |
|
return true; |
|
41
|
|
|
} |
|
42
|
|
|
} |
|
43
|
|
|
return false; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* 判断一个字符串是否以给定字符串结尾 |
|
48
|
|
|
* |
|
49
|
|
|
* @param string $haystack |
|
50
|
|
|
* @param string|array $needles |
|
51
|
|
|
* @return bool |
|
52
|
|
|
*/ |
|
53
|
1 |
|
public static function endsWith($haystack, $needles) |
|
54
|
|
|
{ |
|
55
|
1 |
|
foreach ((array) $needles as $needle) { |
|
56
|
1 |
|
if (substr($haystack, -strlen($needle)) === (string) $needle) { |
|
57
|
1 |
|
return true; |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
return false; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Convert a value to camel case. |
|
65
|
|
|
* |
|
66
|
|
|
* @param string $value |
|
67
|
|
|
* @return string |
|
68
|
|
|
*/ |
|
69
|
|
|
public static function camel($value) { |
|
70
|
|
|
if (isset(static::$camelCache[$value])) { |
|
71
|
|
|
return static::$camelCache[$value]; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
return static::$camelCache[$value] = lcfirst(static::studly($value)); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Convert a value to studly caps case. |
|
79
|
|
|
* |
|
80
|
|
|
* @param string $value |
|
81
|
|
|
* @return string |
|
82
|
|
|
*/ |
|
83
|
1 |
|
public static function studly($value) { |
|
84
|
1 |
|
$key = $value; |
|
85
|
|
|
|
|
86
|
1 |
|
if (isset(static::$studlyCache[$key])) { |
|
87
|
|
|
return static::$studlyCache[$key]; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
1 |
|
$value = ucwords(str_replace(['-', '_'], ' ', $value)); |
|
91
|
|
|
|
|
92
|
1 |
|
return static::$studlyCache[$key] = str_replace(' ', '', $value); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* Cap a string with a single instance of a given value. |
|
97
|
|
|
* |
|
98
|
|
|
* @param string $value |
|
99
|
|
|
* @param string $cap |
|
100
|
|
|
* @return string |
|
101
|
|
|
*/ |
|
102
|
|
|
public static function finish($value, $cap) { |
|
103
|
|
|
$quoted = preg_quote($cap, '/'); |
|
104
|
|
|
|
|
105
|
|
|
return preg_replace('/(?:' . $quoted . ')+$/u', '', $value) . $cap; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* Determine if a given string matches a given pattern. |
|
110
|
|
|
* |
|
111
|
|
|
* @param string $pattern |
|
112
|
|
|
* @param string $value |
|
113
|
|
|
* @return bool |
|
114
|
|
|
*/ |
|
115
|
|
|
public static function is($pattern, $value) { |
|
116
|
|
|
if ($pattern == $value) { |
|
117
|
|
|
return true; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
$pattern = preg_quote($pattern, '#'); |
|
121
|
|
|
|
|
122
|
|
|
// Asterisks are translated into zero-or-more regular expression wildcards |
|
123
|
|
|
// to make it convenient to check if the strings starts with the given |
|
124
|
|
|
// pattern such as "library/*", making any string check convenient. |
|
125
|
|
|
$pattern = str_replace('\*', '.*', $pattern); |
|
126
|
|
|
|
|
127
|
|
|
return (bool)preg_match('#^' . $pattern . '\z#u', $value); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* Convert a string to kebab case. |
|
132
|
|
|
* |
|
133
|
|
|
* @param string $value |
|
134
|
|
|
* @return string |
|
135
|
|
|
*/ |
|
136
|
|
|
public static function kebab($value) { |
|
137
|
|
|
return static::snake($value, '-'); |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* Convert a string to snake case. |
|
142
|
|
|
* |
|
143
|
|
|
* @param string $value |
|
144
|
|
|
* @param string $delimiter |
|
145
|
|
|
* @return string |
|
146
|
|
|
*/ |
|
147
|
|
|
public static function snake($value, $delimiter = '_') { |
|
148
|
|
|
$key = $value; |
|
149
|
|
|
|
|
150
|
|
|
if (isset(static::$snakeCache[$key][$delimiter])) { |
|
151
|
|
|
return static::$snakeCache[$key][$delimiter]; |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
if (!ctype_lower($value)) { |
|
155
|
|
|
$value = preg_replace('/\s+/u', '', $value); |
|
156
|
|
|
|
|
157
|
|
|
$value = static::lower(preg_replace('/(.)(?=[A-Z])/u', '$1' . $delimiter, $value)); |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
return static::$snakeCache[$key][$delimiter] = $value; |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
/** |
|
164
|
|
|
* Convert the given string to lower-case. |
|
165
|
|
|
* |
|
166
|
|
|
* @param string $value |
|
167
|
|
|
* @return string |
|
168
|
|
|
*/ |
|
169
|
|
|
public static function lower($value) { |
|
170
|
|
|
return mb_strtolower($value, 'UTF-8'); |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
/** |
|
174
|
|
|
* Limit the number of characters in a string. |
|
175
|
|
|
* |
|
176
|
|
|
* @param string $value |
|
177
|
|
|
* @param int $limit |
|
178
|
|
|
* @param string $end |
|
179
|
|
|
* @return string |
|
180
|
|
|
*/ |
|
181
|
|
|
public static function limit($value, $limit = 100, $end = '...') { |
|
182
|
|
|
if (mb_strwidth($value, 'UTF-8') <= $limit) { |
|
183
|
|
|
return $value; |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
return rtrim(mb_strimwidth($value, 0, $limit, '', 'UTF-8')) . $end; |
|
187
|
|
|
} |
|
188
|
|
|
|
|
189
|
|
|
/** |
|
190
|
|
|
* Limit the number of words in a string. |
|
191
|
|
|
* |
|
192
|
|
|
* @param string $value |
|
193
|
|
|
* @param int $words |
|
194
|
|
|
* @param string $end |
|
195
|
|
|
* @return string |
|
196
|
|
|
*/ |
|
197
|
|
|
public static function words($value, $words = 100, $end = '...') { |
|
198
|
|
|
preg_match('/^\s*+(?:\S++\s*+){1,' . $words . '}/u', $value, $matches); |
|
199
|
|
|
|
|
200
|
|
|
if (!isset($matches[0]) || static::length($value) === static::length($matches[0])) { |
|
201
|
|
|
return $value; |
|
202
|
|
|
} |
|
203
|
|
|
|
|
204
|
|
|
return rtrim($matches[0]) . $end; |
|
205
|
|
|
} |
|
206
|
|
|
|
|
207
|
|
|
/** |
|
208
|
|
|
* Return the length of the given string. |
|
209
|
|
|
* |
|
210
|
|
|
* @param string $value |
|
211
|
|
|
* @return int |
|
212
|
|
|
*/ |
|
213
|
|
|
public static function length($value) { |
|
214
|
|
|
return mb_strlen($value); |
|
215
|
|
|
} |
|
216
|
|
|
|
|
217
|
|
|
/** |
|
218
|
|
|
* Parse a Class@method style callback into class and method. |
|
219
|
|
|
* |
|
220
|
|
|
* @param string $callback |
|
221
|
|
|
* @param string|null $default |
|
222
|
|
|
* @return array |
|
223
|
|
|
*/ |
|
224
|
|
|
public static function parseCallback($callback, $default = null) { |
|
225
|
|
|
return static::contains($callback, '@') ? explode('@', $callback, 2) : [$callback, $default]; |
|
226
|
|
|
} |
|
227
|
|
|
|
|
228
|
|
|
/** |
|
229
|
|
|
* 判断一个字符串是否包含于另一个字符中 |
|
230
|
|
|
* |
|
231
|
|
|
* @param string $haystack |
|
232
|
|
|
* @param string|array $needles |
|
233
|
|
|
* @return bool |
|
234
|
|
|
*/ |
|
235
|
1 |
|
public static function contains($haystack, $needles) { |
|
236
|
1 |
|
foreach ((array)$needles as $needle) { |
|
237
|
1 |
|
if ($needle != '' && mb_strpos($haystack, $needle) !== false) { |
|
238
|
1 |
|
return true; |
|
239
|
|
|
} |
|
240
|
|
|
} |
|
241
|
|
|
return false; |
|
242
|
|
|
} |
|
243
|
|
|
|
|
244
|
|
|
/** |
|
245
|
|
|
* Get the plural form of an English word. |
|
246
|
|
|
* |
|
247
|
|
|
* @param string $value |
|
248
|
|
|
* @param int $count |
|
249
|
|
|
* @return string |
|
250
|
|
|
*/ |
|
251
|
|
|
public static function plural($value, $count = 2) { |
|
252
|
|
|
return Pluralizer::plural($value, $count); |
|
253
|
|
|
} |
|
254
|
|
|
|
|
255
|
|
|
/** |
|
256
|
|
|
* Generate a "random" alpha-numeric string. |
|
257
|
|
|
* |
|
258
|
|
|
* Should not be considered sufficient for cryptography, etc. |
|
259
|
|
|
* |
|
260
|
|
|
* @deprecated since version 5.3. Use the "random" method directly. |
|
261
|
|
|
* |
|
262
|
|
|
* @param int $length |
|
263
|
|
|
* @return string |
|
264
|
|
|
*/ |
|
265
|
|
|
public static function quickRandom($length = 16) { |
|
266
|
|
|
if (PHP_MAJOR_VERSION > 5) { |
|
267
|
|
|
return static::random($length); |
|
268
|
|
|
} |
|
269
|
|
|
|
|
270
|
|
|
$pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; |
|
271
|
|
|
|
|
272
|
|
|
return substr(str_shuffle(str_repeat($pool, $length)), 0, $length); |
|
273
|
|
|
} |
|
274
|
|
|
|
|
275
|
|
|
/** |
|
276
|
|
|
* Generate a more truly "random" alpha-numeric string. |
|
277
|
|
|
* |
|
278
|
|
|
* @param int $length |
|
279
|
|
|
* @return string |
|
280
|
|
|
*/ |
|
281
|
|
|
public static function random($length = 16) { |
|
282
|
|
|
$string = ''; |
|
283
|
|
|
|
|
284
|
|
|
while (($len = strlen($string)) < $length) { |
|
285
|
|
|
$size = $length - $len; |
|
286
|
|
|
|
|
287
|
|
|
$bytes = random_bytes($size); |
|
288
|
|
|
|
|
289
|
|
|
$string .= substr(str_replace(['/', '+', '='], '', base64_encode($bytes)), 0, $size); |
|
290
|
|
|
} |
|
291
|
|
|
|
|
292
|
|
|
return $string; |
|
293
|
|
|
} |
|
294
|
|
|
|
|
295
|
|
|
/** |
|
296
|
|
|
* Replace a given value in the string sequentially with an array. |
|
297
|
|
|
* |
|
298
|
|
|
* @param string $search |
|
299
|
|
|
* @param array $replace |
|
300
|
|
|
* @param string $subject |
|
301
|
|
|
* @return string |
|
302
|
|
|
*/ |
|
303
|
|
|
public static function replaceArray($search, array $replace, $subject) { |
|
304
|
|
|
foreach ($replace as $value) { |
|
305
|
|
|
$subject = static::replaceFirst($search, $value, $subject); |
|
306
|
|
|
} |
|
307
|
|
|
|
|
308
|
|
|
return $subject; |
|
309
|
|
|
} |
|
310
|
|
|
|
|
311
|
|
|
/** |
|
312
|
|
|
* Replace the first occurrence of a given value in the string. |
|
313
|
|
|
* |
|
314
|
|
|
* @param string $search |
|
315
|
|
|
* @param string $replace |
|
316
|
|
|
* @param string $subject |
|
317
|
|
|
* @return string |
|
318
|
|
|
*/ |
|
319
|
|
|
public static function replaceFirst($search, $replace, $subject) { |
|
320
|
|
|
$position = strpos($subject, $search); |
|
321
|
|
|
|
|
322
|
|
|
if ($position !== false) { |
|
323
|
|
|
return substr_replace($subject, $replace, $position, strlen($search)); |
|
324
|
|
|
} |
|
325
|
|
|
|
|
326
|
|
|
return $subject; |
|
327
|
|
|
} |
|
328
|
|
|
|
|
329
|
|
|
/** |
|
330
|
|
|
* Replace the last occurrence of a given value in the string. |
|
331
|
|
|
* |
|
332
|
|
|
* @param string $search |
|
333
|
|
|
* @param string $replace |
|
334
|
|
|
* @param string $subject |
|
335
|
|
|
* @return string |
|
336
|
|
|
*/ |
|
337
|
|
|
public static function replaceLast($search, $replace, $subject) { |
|
338
|
|
|
$position = strrpos($subject, $search); |
|
339
|
|
|
|
|
340
|
|
|
if ($position !== false) { |
|
341
|
|
|
return substr_replace($subject, $replace, $position, strlen($search)); |
|
342
|
|
|
} |
|
343
|
|
|
|
|
344
|
|
|
return $subject; |
|
345
|
|
|
} |
|
346
|
|
|
|
|
347
|
|
|
/** |
|
348
|
|
|
* Convert the given string to title case. |
|
349
|
|
|
* |
|
350
|
|
|
* @param string $value |
|
351
|
|
|
* @return string |
|
352
|
|
|
*/ |
|
353
|
|
|
public static function title($value) { |
|
354
|
|
|
return mb_convert_case($value, MB_CASE_TITLE, 'UTF-8'); |
|
355
|
|
|
} |
|
356
|
|
|
|
|
357
|
|
|
/** |
|
358
|
|
|
* Get the singular form of an English word. |
|
359
|
|
|
* |
|
360
|
|
|
* @param string $value |
|
361
|
|
|
* @return string |
|
362
|
|
|
*/ |
|
363
|
|
|
public static function singular($value) { |
|
364
|
|
|
return Pluralizer::singular($value); |
|
365
|
|
|
} |
|
366
|
|
|
|
|
367
|
|
|
/** |
|
368
|
|
|
* Generate a URL friendly "slug" from a given string. |
|
369
|
|
|
* |
|
370
|
|
|
* @param string $title |
|
371
|
|
|
* @param string $separator |
|
372
|
|
|
* @return string |
|
373
|
|
|
*/ |
|
374
|
|
|
public static function slug($title, $separator = '-') { |
|
375
|
|
|
$title = static::ascii($title); |
|
376
|
|
|
|
|
377
|
|
|
// Convert all dashes/underscores into separator |
|
378
|
|
|
$flip = $separator == '-' ? '_' : '-'; |
|
379
|
|
|
|
|
380
|
|
|
$title = preg_replace('![' . preg_quote($flip) . ']+!u', $separator, $title); |
|
381
|
|
|
|
|
382
|
|
|
// Remove all characters that are not the separator, letters, numbers, or whitespace. |
|
383
|
|
|
$title = preg_replace('![^' . preg_quote($separator) . '\pL\pN\s]+!u', '', mb_strtolower($title)); |
|
384
|
|
|
|
|
385
|
|
|
// Replace all separator characters and whitespace by a single separator |
|
386
|
|
|
$title = preg_replace('![' . preg_quote($separator) . '\s]+!u', $separator, $title); |
|
387
|
|
|
|
|
388
|
|
|
return trim($title, $separator); |
|
389
|
|
|
} |
|
390
|
|
|
|
|
391
|
|
|
/** |
|
392
|
|
|
* Transliterate a UTF-8 value to ASCII. |
|
393
|
|
|
* |
|
394
|
|
|
* @param string $value |
|
395
|
|
|
* @return string |
|
396
|
|
|
*/ |
|
397
|
|
|
public static function ascii($value) { |
|
398
|
|
|
foreach (static::charsArray() as $key => $val) { |
|
399
|
|
|
$value = str_replace($val, $key, $value); |
|
400
|
|
|
} |
|
401
|
|
|
|
|
402
|
|
|
return preg_replace('/[^\x20-\x7E]/u', '', $value); |
|
403
|
|
|
} |
|
404
|
|
|
|
|
405
|
|
|
/** |
|
406
|
|
|
* Returns the replacements for the ascii method. |
|
407
|
|
|
* |
|
408
|
|
|
* Note: Adapted from Stringy\Stringy. |
|
409
|
|
|
* |
|
410
|
|
|
* @see https://github.com/danielstjules/Stringy/blob/2.3.1/LICENSE.txt |
|
411
|
|
|
* |
|
412
|
|
|
* @return array |
|
413
|
|
|
*/ |
|
414
|
|
|
protected static function charsArray() { |
|
415
|
|
|
static $charsArray; |
|
416
|
|
|
|
|
417
|
|
|
if (isset($charsArray)) { |
|
418
|
|
|
return $charsArray; |
|
419
|
|
|
} |
|
420
|
|
|
|
|
421
|
|
|
return $charsArray = [ |
|
422
|
|
|
'0' => ['°', '₀', '۰'], |
|
423
|
|
|
'1' => ['¹', '₁', '۱'], |
|
424
|
|
|
'2' => ['²', '₂', '۲'], |
|
425
|
|
|
'3' => ['³', '₃', '۳'], |
|
426
|
|
|
'4' => ['⁴', '₄', '۴', '٤'], |
|
427
|
|
|
'5' => ['⁵', '₅', '۵', '٥'], |
|
428
|
|
|
'6' => ['⁶', '₆', '۶', '٦'], |
|
429
|
|
|
'7' => ['⁷', '₇', '۷'], |
|
430
|
|
|
'8' => ['⁸', '₈', '۸'], |
|
431
|
|
|
'9' => ['⁹', '₉', '۹'], |
|
432
|
|
|
'a' => ['à', 'á', 'ả', 'ã', 'ạ', 'ă', 'ắ', 'ằ', 'ẳ', 'ẵ', 'ặ', 'â', 'ấ', 'ầ', 'ẩ', 'ẫ', 'ậ', 'ā', 'ą', 'å', 'α', 'ά', 'ἀ', 'ἁ', 'ἂ', 'ἃ', 'ἄ', 'ἅ', 'ἆ', 'ἇ', 'ᾀ', 'ᾁ', 'ᾂ', 'ᾃ', 'ᾄ', 'ᾅ', 'ᾆ', 'ᾇ', 'ὰ', 'ά', 'ᾰ', 'ᾱ', 'ᾲ', 'ᾳ', 'ᾴ', 'ᾶ', 'ᾷ', 'а', 'أ', 'အ', 'ာ', 'ါ', 'ǻ', 'ǎ', 'ª', 'ა', 'अ', 'ا'], |
|
433
|
|
|
'b' => ['б', 'β', 'Ъ', 'Ь', 'ب', 'ဗ', 'ბ'], |
|
434
|
|
|
'c' => ['ç', 'ć', 'č', 'ĉ', 'ċ'], |
|
435
|
|
|
'd' => ['ď', 'ð', 'đ', 'ƌ', 'ȡ', 'ɖ', 'ɗ', 'ᵭ', 'ᶁ', 'ᶑ', 'д', 'δ', 'د', 'ض', 'ဍ', 'ဒ', 'დ'], |
|
436
|
|
|
'e' => ['é', 'è', 'ẻ', 'ẽ', 'ẹ', 'ê', 'ế', 'ề', 'ể', 'ễ', 'ệ', 'ë', 'ē', 'ę', 'ě', 'ĕ', 'ė', 'ε', 'έ', 'ἐ', 'ἑ', 'ἒ', 'ἓ', 'ἔ', 'ἕ', 'ὲ', 'έ', 'е', 'ё', 'э', 'є', 'ə', 'ဧ', 'ေ', 'ဲ', 'ე', 'ए', 'إ', 'ئ'], |
|
437
|
|
|
'f' => ['ф', 'φ', 'ف', 'ƒ', 'ფ'], |
|
438
|
|
|
'g' => ['ĝ', 'ğ', 'ġ', 'ģ', 'г', 'ґ', 'γ', 'ဂ', 'გ', 'گ'], |
|
439
|
|
|
'h' => ['ĥ', 'ħ', 'η', 'ή', 'ح', 'ه', 'ဟ', 'ှ', 'ჰ'], |
|
440
|
|
|
'i' => ['í', 'ì', 'ỉ', 'ĩ', 'ị', 'î', 'ï', 'ī', 'ĭ', 'į', 'ı', 'ι', 'ί', 'ϊ', 'ΐ', 'ἰ', 'ἱ', 'ἲ', 'ἳ', 'ἴ', 'ἵ', 'ἶ', 'ἷ', 'ὶ', 'ί', 'ῐ', 'ῑ', 'ῒ', 'ΐ', 'ῖ', 'ῗ', 'і', 'ї', 'и', 'ဣ', 'ိ', 'ီ', 'ည်', 'ǐ', 'ი', 'इ'], |
|
441
|
|
|
'j' => ['ĵ', 'ј', 'Ј', 'ჯ', 'ج'], |
|
442
|
|
|
'k' => ['ķ', 'ĸ', 'к', 'κ', 'Ķ', 'ق', 'ك', 'က', 'კ', 'ქ', 'ک'], |
|
443
|
|
|
'l' => ['ł', 'ľ', 'ĺ', 'ļ', 'ŀ', 'л', 'λ', 'ل', 'လ', 'ლ'], |
|
444
|
|
|
'm' => ['м', 'μ', 'م', 'မ', 'მ'], |
|
445
|
|
|
'n' => ['ñ', 'ń', 'ň', 'ņ', 'ʼn', 'ŋ', 'ν', 'н', 'ن', 'န', 'ნ'], |
|
446
|
|
|
'o' => ['ó', 'ò', 'ỏ', 'õ', 'ọ', 'ô', 'ố', 'ồ', 'ổ', 'ỗ', 'ộ', 'ơ', 'ớ', 'ờ', 'ở', 'ỡ', 'ợ', 'ø', 'ō', 'ő', 'ŏ', 'ο', 'ὀ', 'ὁ', 'ὂ', 'ὃ', 'ὄ', 'ὅ', 'ὸ', 'ό', 'о', 'و', 'θ', 'ို', 'ǒ', 'ǿ', 'º', 'ო', 'ओ'], |
|
447
|
|
|
'p' => ['п', 'π', 'ပ', 'პ', 'پ'], |
|
448
|
|
|
'q' => ['ყ'], |
|
449
|
|
|
'r' => ['ŕ', 'ř', 'ŗ', 'р', 'ρ', 'ر', 'რ'], |
|
450
|
|
|
's' => ['ś', 'š', 'ş', 'с', 'σ', 'ș', 'ς', 'س', 'ص', 'စ', 'ſ', 'ს'], |
|
451
|
|
|
't' => ['ť', 'ţ', 'т', 'τ', 'ț', 'ت', 'ط', 'ဋ', 'တ', 'ŧ', 'თ', 'ტ'], |
|
452
|
|
|
'u' => ['ú', 'ù', 'ủ', 'ũ', 'ụ', 'ư', 'ứ', 'ừ', 'ử', 'ữ', 'ự', 'û', 'ū', 'ů', 'ű', 'ŭ', 'ų', 'µ', 'у', 'ဉ', 'ု', 'ူ', 'ǔ', 'ǖ', 'ǘ', 'ǚ', 'ǜ', 'უ', 'उ'], |
|
453
|
|
|
'v' => ['в', 'ვ', 'ϐ'], |
|
454
|
|
|
'w' => ['ŵ', 'ω', 'ώ', 'ဝ', 'ွ'], |
|
455
|
|
|
'x' => ['χ', 'ξ'], |
|
456
|
|
|
'y' => ['ý', 'ỳ', 'ỷ', 'ỹ', 'ỵ', 'ÿ', 'ŷ', 'й', 'ы', 'υ', 'ϋ', 'ύ', 'ΰ', 'ي', 'ယ'], |
|
457
|
|
|
'z' => ['ź', 'ž', 'ż', 'з', 'ζ', 'ز', 'ဇ', 'ზ'], |
|
458
|
|
|
'aa' => ['ع', 'आ', 'آ'], |
|
459
|
|
|
'ae' => ['ä', 'æ', 'ǽ'], |
|
460
|
|
|
'ai' => ['ऐ'], |
|
461
|
|
|
'at' => ['@'], |
|
462
|
|
|
'ch' => ['ч', 'ჩ', 'ჭ', 'چ'], |
|
463
|
|
|
'dj' => ['ђ', 'đ'], |
|
464
|
|
|
'dz' => ['џ', 'ძ'], |
|
465
|
|
|
'ei' => ['ऍ'], |
|
466
|
|
|
'gh' => ['غ', 'ღ'], |
|
467
|
|
|
'ii' => ['ई'], |
|
468
|
|
|
'ij' => ['ij'], |
|
469
|
|
|
'kh' => ['х', 'خ', 'ხ'], |
|
470
|
|
|
'lj' => ['љ'], |
|
471
|
|
|
'nj' => ['њ'], |
|
472
|
|
|
'oe' => ['ö', 'œ', 'ؤ'], |
|
473
|
|
|
'oi' => ['ऑ'], |
|
474
|
|
|
'oii' => ['ऒ'], |
|
475
|
|
|
'ps' => ['ψ'], |
|
476
|
|
|
'sh' => ['ш', 'შ', 'ش'], |
|
477
|
|
|
'shch' => ['щ'], |
|
478
|
|
|
'ss' => ['ß'], |
|
479
|
|
|
'sx' => ['ŝ'], |
|
480
|
|
|
'th' => ['þ', 'ϑ', 'ث', 'ذ', 'ظ'], |
|
481
|
|
|
'ts' => ['ц', 'ც', 'წ'], |
|
482
|
|
|
'ue' => ['ü'], |
|
483
|
|
|
'uu' => ['ऊ'], |
|
484
|
|
|
'ya' => ['я'], |
|
485
|
|
|
'yu' => ['ю'], |
|
486
|
|
|
'zh' => ['ж', 'ჟ', 'ژ'], |
|
487
|
|
|
'(c)' => ['©'], |
|
488
|
|
|
'A' => ['Á', 'À', 'Ả', 'Ã', 'Ạ', 'Ă', 'Ắ', 'Ằ', 'Ẳ', 'Ẵ', 'Ặ', 'Â', 'Ấ', 'Ầ', 'Ẩ', 'Ẫ', 'Ậ', 'Å', 'Ā', 'Ą', 'Α', 'Ά', 'Ἀ', 'Ἁ', 'Ἂ', 'Ἃ', 'Ἄ', 'Ἅ', 'Ἆ', 'Ἇ', 'ᾈ', 'ᾉ', 'ᾊ', 'ᾋ', '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X' => ['Ĥ'], |
|
518
|
|
|
'IJ' => ['IJ'], |
|
519
|
|
|
'JX' => ['Ĵ'], |
|
520
|
|
|
'KH' => ['Х'], |
|
521
|
|
|
'LJ' => ['Љ'], |
|
522
|
|
|
'NJ' => ['Њ'], |
|
523
|
|
|
'OE' => ['Ö', 'Œ'], |
|
524
|
|
|
'PS' => ['Ψ'], |
|
525
|
|
|
'SH' => ['Ш'], |
|
526
|
|
|
'SHCH' => ['Щ'], |
|
527
|
|
|
'SS' => ['ẞ'], |
|
528
|
|
|
'TH' => ['Þ'], |
|
529
|
|
|
'TS' => ['Ц'], |
|
530
|
|
|
'UE' => ['Ü'], |
|
531
|
|
|
'YA' => ['Я'], |
|
532
|
|
|
'YU' => ['Ю'], |
|
533
|
|
|
'ZH' => ['Ж'], |
|
534
|
|
|
' ' => ["\xC2\xA0", "\xE2\x80\x80", "\xE2\x80\x81", "\xE2\x80\x82", "\xE2\x80\x83", "\xE2\x80\x84", "\xE2\x80\x85", "\xE2\x80\x86", "\xE2\x80\x87", "\xE2\x80\x88", "\xE2\x80\x89", "\xE2\x80\x8A", "\xE2\x80\xAF", "\xE2\x81\x9F", "\xE3\x80\x80"], |
|
535
|
|
|
]; |
|
536
|
|
|
} |
|
537
|
|
|
|
|
538
|
|
|
/** |
|
539
|
|
|
* Make a string's first character uppercase. |
|
540
|
|
|
* |
|
541
|
|
|
* @param string $string |
|
542
|
|
|
* @return string |
|
543
|
|
|
*/ |
|
544
|
|
|
public static function ucfirst($string) { |
|
545
|
|
|
return static::upper(static::substr($string, 0, 1)) . static::substr($string, 1); |
|
546
|
|
|
} |
|
547
|
|
|
|
|
548
|
|
|
/** |
|
549
|
|
|
* Convert the given string to upper-case. |
|
550
|
|
|
* |
|
551
|
|
|
* @param string $value |
|
552
|
|
|
* @return string |
|
553
|
|
|
*/ |
|
554
|
|
|
public static function upper($value) { |
|
555
|
|
|
return mb_strtoupper($value, 'UTF-8'); |
|
556
|
|
|
} |
|
557
|
|
|
|
|
558
|
|
|
/** |
|
559
|
|
|
* Returns the portion of string specified by the start and length parameters. |
|
560
|
|
|
* |
|
561
|
|
|
* @param string $string |
|
562
|
|
|
* @param int $start |
|
563
|
|
|
* @param int|null $length |
|
564
|
|
|
* @return string |
|
565
|
|
|
*/ |
|
566
|
|
|
public static function substr($string, $start, $length = null) { |
|
567
|
|
|
return mb_substr($string, $start, $length, 'UTF-8'); |
|
568
|
|
|
} |
|
569
|
|
|
} |