Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like UTF8 often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use UTF8, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
12 | final class UTF8 |
||
13 | { |
||
14 | // (CRLF|([ZWNJ-ZWJ]|T+|L*(LV?V+|LV|LVT)T*|L+|[^Control])[Extend]*|[Control]) |
||
15 | // This regular expression is a work around for http://bugs.exim.org/1279 |
||
16 | const GRAPHEME_CLUSTER_RX = '(?:\r\n|(?:[ -~\x{200C}\x{200D}]|[ᆨ-ᇹ]+|[ᄀ-ᅟ]*(?:[가개갸걔거게겨계고과괘괴교구궈궤귀규그긔기까깨꺄꺠꺼께껴꼐꼬꽈꽤꾀꾜꾸꿔꿰뀌뀨끄끠끼나내냐냬너네녀녜노놔놰뇌뇨누눠눼뉘뉴느늬니다대댜댸더데뎌뎨도돠돼되됴두둬뒈뒤듀드듸디따때땨떄떠떼뗘뗴또똬뙈뙤뚀뚜뚸뛔뛰뜌뜨띄띠라래랴럐러레려례로롸뢔뢰료루뤄뤠뤼류르릐리마매먀먜머메며몌모뫄뫠뫼묘무뭐뭬뮈뮤므믜미바배뱌뱨버베벼볘보봐봬뵈뵤부붜붸뷔뷰브븨비빠빼뺘뺴뻐뻬뼈뼤뽀뽜뽸뾔뾰뿌뿨쀄쀠쀼쁘쁴삐사새샤섀서세셔셰소솨쇄쇠쇼수숴쉐쉬슈스싀시싸쌔쌰썌써쎄쎠쎼쏘쏴쐐쐬쑈쑤쒀쒜쒸쓔쓰씌씨아애야얘어에여예오와왜외요우워웨위유으의이자재쟈쟤저제져졔조좌좨죄죠주줘줴쥐쥬즈즤지짜째쨔쨰쩌쩨쪄쪠쪼쫘쫴쬐쬬쭈쭤쮀쮜쮸쯔쯰찌차채챠챼처체쳐쳬초촤쵀최쵸추춰췌취츄츠츼치카캐캬컈커케켜켸코콰쾌쾨쿄쿠쿼퀘퀴큐크킈키타태탸턔터테텨톄토톼퇘퇴툐투퉈퉤튀튜트틔티파패퍄퍠퍼페펴폐포퐈퐤푀표푸풔풰퓌퓨프픠피하해햐햬허헤혀혜호화홰회효후훠훼휘휴흐희히]?[ᅠ-ᆢ]+|[가-힣])[ᆨ-ᇹ]*|[ᄀ-ᅟ]+|[^\p{Cc}\p{Cf}\p{Zl}\p{Zp}])[\p{Mn}\p{Me}\x{09BE}\x{09D7}\x{0B3E}\x{0B57}\x{0BBE}\x{0BD7}\x{0CC2}\x{0CD5}\x{0CD6}\x{0D3E}\x{0D57}\x{0DCF}\x{0DDF}\x{200C}\x{200D}\x{1D165}\x{1D16E}-\x{1D172}]*|[\p{Cc}\p{Cf}\p{Zl}\p{Zp}])'; |
||
17 | |||
18 | /** |
||
19 | * Bom => Byte-Length |
||
20 | * |
||
21 | * INFO: https://en.wikipedia.org/wiki/Byte_order_mark |
||
22 | * |
||
23 | * @var array |
||
24 | */ |
||
25 | private static $BOM = [ |
||
26 | "\xef\xbb\xbf" => 3, // UTF-8 BOM |
||
27 | '' => 6, // UTF-8 BOM as "WINDOWS-1252" (one char has [maybe] more then one byte ...) |
||
28 | "\x00\x00\xfe\xff" => 4, // UTF-32 (BE) BOM |
||
29 | ' þÿ' => 6, // UTF-32 (BE) BOM as "WINDOWS-1252" |
||
30 | "\xff\xfe\x00\x00" => 4, // UTF-32 (LE) BOM |
||
31 | 'ÿþ ' => 6, // UTF-32 (LE) BOM as "WINDOWS-1252" |
||
32 | "\xfe\xff" => 2, // UTF-16 (BE) BOM |
||
33 | 'þÿ' => 4, // UTF-16 (BE) BOM as "WINDOWS-1252" |
||
34 | "\xff\xfe" => 2, // UTF-16 (LE) BOM |
||
35 | 'ÿþ' => 4, // UTF-16 (LE) BOM as "WINDOWS-1252" |
||
36 | ]; |
||
37 | |||
38 | /** |
||
39 | * Numeric code point => UTF-8 Character |
||
40 | * |
||
41 | * url: http://www.w3schools.com/charsets/ref_utf_punctuation.asp |
||
42 | * |
||
43 | * @var array |
||
44 | */ |
||
45 | private static $WHITESPACE = [ |
||
46 | // NUL Byte |
||
47 | 0 => "\x0", |
||
48 | // Tab |
||
49 | 9 => "\x9", |
||
50 | // New Line |
||
51 | 10 => "\xa", |
||
52 | // Vertical Tab |
||
53 | 11 => "\xb", |
||
54 | // Carriage Return |
||
55 | 13 => "\xd", |
||
56 | // Ordinary Space |
||
57 | 32 => "\x20", |
||
58 | // NO-BREAK SPACE |
||
59 | 160 => "\xc2\xa0", |
||
60 | // OGHAM SPACE MARK |
||
61 | 5760 => "\xe1\x9a\x80", |
||
62 | // MONGOLIAN VOWEL SEPARATOR |
||
63 | 6158 => "\xe1\xa0\x8e", |
||
64 | // EN QUAD |
||
65 | 8192 => "\xe2\x80\x80", |
||
66 | // EM QUAD |
||
67 | 8193 => "\xe2\x80\x81", |
||
68 | // EN SPACE |
||
69 | 8194 => "\xe2\x80\x82", |
||
70 | // EM SPACE |
||
71 | 8195 => "\xe2\x80\x83", |
||
72 | // THREE-PER-EM SPACE |
||
73 | 8196 => "\xe2\x80\x84", |
||
74 | // FOUR-PER-EM SPACE |
||
75 | 8197 => "\xe2\x80\x85", |
||
76 | // SIX-PER-EM SPACE |
||
77 | 8198 => "\xe2\x80\x86", |
||
78 | // FIGURE SPACE |
||
79 | 8199 => "\xe2\x80\x87", |
||
80 | // PUNCTUATION SPACE |
||
81 | 8200 => "\xe2\x80\x88", |
||
82 | // THIN SPACE |
||
83 | 8201 => "\xe2\x80\x89", |
||
84 | //HAIR SPACE |
||
85 | 8202 => "\xe2\x80\x8a", |
||
86 | // LINE SEPARATOR |
||
87 | 8232 => "\xe2\x80\xa8", |
||
88 | // PARAGRAPH SEPARATOR |
||
89 | 8233 => "\xe2\x80\xa9", |
||
90 | // NARROW NO-BREAK SPACE |
||
91 | 8239 => "\xe2\x80\xaf", |
||
92 | // MEDIUM MATHEMATICAL SPACE |
||
93 | 8287 => "\xe2\x81\x9f", |
||
94 | // IDEOGRAPHIC SPACE |
||
95 | 12288 => "\xe3\x80\x80", |
||
96 | ]; |
||
97 | |||
98 | /** |
||
99 | * @var array |
||
100 | */ |
||
101 | private static $WHITESPACE_TABLE = [ |
||
102 | 'SPACE' => "\x20", |
||
103 | 'NO-BREAK SPACE' => "\xc2\xa0", |
||
104 | 'OGHAM SPACE MARK' => "\xe1\x9a\x80", |
||
105 | 'EN QUAD' => "\xe2\x80\x80", |
||
106 | 'EM QUAD' => "\xe2\x80\x81", |
||
107 | 'EN SPACE' => "\xe2\x80\x82", |
||
108 | 'EM SPACE' => "\xe2\x80\x83", |
||
109 | 'THREE-PER-EM SPACE' => "\xe2\x80\x84", |
||
110 | 'FOUR-PER-EM SPACE' => "\xe2\x80\x85", |
||
111 | 'SIX-PER-EM SPACE' => "\xe2\x80\x86", |
||
112 | 'FIGURE SPACE' => "\xe2\x80\x87", |
||
113 | 'PUNCTUATION SPACE' => "\xe2\x80\x88", |
||
114 | 'THIN SPACE' => "\xe2\x80\x89", |
||
115 | 'HAIR SPACE' => "\xe2\x80\x8a", |
||
116 | 'LINE SEPARATOR' => "\xe2\x80\xa8", |
||
117 | 'PARAGRAPH SEPARATOR' => "\xe2\x80\xa9", |
||
118 | 'ZERO WIDTH SPACE' => "\xe2\x80\x8b", |
||
119 | 'NARROW NO-BREAK SPACE' => "\xe2\x80\xaf", |
||
120 | 'MEDIUM MATHEMATICAL SPACE' => "\xe2\x81\x9f", |
||
121 | 'IDEOGRAPHIC SPACE' => "\xe3\x80\x80", |
||
122 | ]; |
||
123 | |||
124 | /** |
||
125 | * bidirectional text chars |
||
126 | * |
||
127 | * url: https://www.w3.org/International/questions/qa-bidi-unicode-controls |
||
128 | * |
||
129 | * @var array |
||
130 | */ |
||
131 | private static $BIDI_UNI_CODE_CONTROLS_TABLE = [ |
||
132 | // LEFT-TO-RIGHT EMBEDDING (use -> dir = "ltr") |
||
133 | 8234 => "\xE2\x80\xAA", |
||
134 | // RIGHT-TO-LEFT EMBEDDING (use -> dir = "rtl") |
||
135 | 8235 => "\xE2\x80\xAB", |
||
136 | // POP DIRECTIONAL FORMATTING // (use -> </bdo>) |
||
137 | 8236 => "\xE2\x80\xAC", |
||
138 | // LEFT-TO-RIGHT OVERRIDE // (use -> <bdo dir = "ltr">) |
||
139 | 8237 => "\xE2\x80\xAD", |
||
140 | // RIGHT-TO-LEFT OVERRIDE // (use -> <bdo dir = "rtl">) |
||
141 | 8238 => "\xE2\x80\xAE", |
||
142 | // LEFT-TO-RIGHT ISOLATE // (use -> dir = "ltr") |
||
143 | 8294 => "\xE2\x81\xA6", |
||
144 | // RIGHT-TO-LEFT ISOLATE // (use -> dir = "rtl") |
||
145 | 8295 => "\xE2\x81\xA7", |
||
146 | // FIRST STRONG ISOLATE // (use -> dir = "auto") |
||
147 | 8296 => "\xE2\x81\xA8", |
||
148 | // POP DIRECTIONAL ISOLATE |
||
149 | 8297 => "\xE2\x81\xA9", |
||
150 | ]; |
||
151 | |||
152 | /** |
||
153 | * @var array |
||
154 | */ |
||
155 | private static $COMMON_CASE_FOLD = [ |
||
156 | 'ſ' => 's', |
||
157 | "\xCD\x85" => 'ι', |
||
158 | 'ς' => 'σ', |
||
159 | "\xCF\x90" => 'β', |
||
160 | "\xCF\x91" => 'θ', |
||
161 | "\xCF\x95" => 'φ', |
||
162 | "\xCF\x96" => 'π', |
||
163 | "\xCF\xB0" => 'κ', |
||
164 | "\xCF\xB1" => 'ρ', |
||
165 | "\xCF\xB5" => 'ε', |
||
166 | "\xE1\xBA\x9B" => "\xE1\xB9\xA1", |
||
167 | "\xE1\xBE\xBE" => 'ι', |
||
168 | ]; |
||
169 | |||
170 | /** |
||
171 | * @var array |
||
172 | */ |
||
173 | private static $SUPPORT = []; |
||
174 | |||
175 | /** |
||
176 | * @var null|array |
||
177 | */ |
||
178 | private static $UTF8_MSWORD; |
||
179 | |||
180 | /** |
||
181 | * @var null|array |
||
182 | */ |
||
183 | private static $BROKEN_UTF8_FIX; |
||
184 | |||
185 | /** |
||
186 | * @var null|array |
||
187 | */ |
||
188 | private static $WIN1252_TO_UTF8; |
||
189 | |||
190 | /** |
||
191 | * @var null|array |
||
192 | */ |
||
193 | private static $ENCODINGS; |
||
194 | |||
195 | /** |
||
196 | * @var null|array |
||
197 | */ |
||
198 | private static $ORD; |
||
199 | |||
200 | /** |
||
201 | * @var null|array |
||
202 | */ |
||
203 | private static $CHR; |
||
204 | |||
205 | /** |
||
206 | * __construct() |
||
207 | */ |
||
208 | 16 | public function __construct() |
|
209 | { |
||
210 | 16 | self::checkForSupport(); |
|
211 | 16 | } |
|
212 | |||
213 | /** |
||
214 | * Return the character at the specified position: $str[1] like functionality. |
||
215 | * |
||
216 | * @param string $str <p>A UTF-8 string.</p> |
||
217 | * @param int $pos <p>The position of character to return.</p> |
||
218 | * |
||
219 | * @return string <p>Single Multi-Byte character.</p> |
||
220 | */ |
||
221 | 2 | public static function access(string $str, int $pos): string |
|
233 | |||
234 | /** |
||
235 | * Prepends UTF-8 BOM character to the string and returns the whole string. |
||
236 | * |
||
237 | * INFO: If BOM already existed there, the Input string is returned. |
||
238 | * |
||
239 | * @param string $str <p>The input string.</p> |
||
240 | * |
||
241 | * @return string <p>The output string that contains BOM.</p> |
||
242 | */ |
||
243 | 1 | public static function add_bom_to_string(string $str): string |
|
251 | |||
252 | /** |
||
253 | * Changes all keys in an array. |
||
254 | * |
||
255 | * @param array $array <p>The array to work on</p> |
||
256 | * @param int $case [optional] <p> Either <strong>CASE_UPPER</strong><br> |
||
257 | * or <strong>CASE_LOWER</strong> (default)</p> |
||
258 | * |
||
259 | * @return array <p>An array with its keys lower or uppercased.</p> |
||
260 | */ |
||
261 | 1 | public static function array_change_key_case(array $array, int $case = CASE_LOWER): array |
|
284 | |||
285 | /** |
||
286 | * Convert binary into an string. |
||
287 | * |
||
288 | * @param mixed $bin 1|0 |
||
289 | * |
||
290 | * @return string |
||
291 | */ |
||
292 | 1 | public static function binary_to_str($bin): string |
|
305 | |||
306 | /** |
||
307 | * Returns the UTF-8 Byte Order Mark Character. |
||
308 | * |
||
309 | * INFO: take a look at UTF8::$bom for e.g. UTF-16 and UTF-32 BOM values |
||
310 | * |
||
311 | * @return string UTF-8 Byte Order Mark |
||
312 | */ |
||
313 | 2 | public static function bom(): string |
|
317 | |||
318 | /** |
||
319 | * @alias of UTF8::chr_map() |
||
320 | * |
||
321 | * @see UTF8::chr_map() |
||
322 | * |
||
323 | * @param string|array $callback |
||
324 | * @param string $str |
||
325 | * |
||
326 | * @return array |
||
327 | */ |
||
328 | 1 | public static function callback($callback, string $str): array |
|
332 | |||
333 | /** |
||
334 | * This method will auto-detect your server environment for UTF-8 support. |
||
335 | * |
||
336 | * INFO: You don't need to run it manually, it will be triggered if it's needed. |
||
337 | */ |
||
338 | 19 | public static function checkForSupport() |
|
369 | |||
370 | /** |
||
371 | * Generates a UTF-8 encoded character from the given code point. |
||
372 | * |
||
373 | * INFO: opposite to UTF8::ord() |
||
374 | * |
||
375 | * @param int|string $code_point <p>The code point for which to generate a character.</p> |
||
376 | * @param string $encoding [optional] <p>Default is UTF-8</p> |
||
377 | * |
||
378 | * @return string|null <p>Multi-Byte character, returns null on failure or empty input.</p> |
||
379 | */ |
||
380 | 10 | public static function chr($code_point, string $encoding = 'UTF-8') |
|
381 | { |
||
382 | // init |
||
383 | 10 | static $CHAR_CACHE = []; |
|
384 | |||
385 | 10 | if (!isset(self::$SUPPORT['already_checked_via_portable_utf8'])) { |
|
386 | self::checkForSupport(); |
||
387 | } |
||
388 | |||
389 | 10 | if ($encoding !== 'UTF-8' && $encoding !== 'CP850') { |
|
390 | 2 | $encoding = self::normalize_encoding($encoding, 'UTF-8'); |
|
391 | } |
||
392 | |||
393 | View Code Duplication | if ( |
|
394 | 10 | $encoding !== 'UTF-8' |
|
395 | && |
||
396 | 10 | $encoding !== 'ISO-8859-1' |
|
397 | && |
||
398 | 10 | $encoding !== 'WINDOWS-1252' |
|
399 | && |
||
400 | 10 | self::$SUPPORT['mbstring'] === false |
|
401 | ) { |
||
402 | \trigger_error('UTF8::chr() without mbstring cannot handle "' . $encoding . '" encoding', E_USER_WARNING); |
||
403 | } |
||
404 | |||
405 | 10 | $cacheKey = $code_point . $encoding; |
|
406 | 10 | if (isset($CHAR_CACHE[$cacheKey]) === true) { |
|
407 | 8 | return $CHAR_CACHE[$cacheKey]; |
|
408 | } |
||
409 | |||
410 | 9 | if ($code_point <= 127) { // use "simple"-char only until "\x80" |
|
411 | |||
412 | 7 | if (self::$CHR === null) { |
|
413 | self::$CHR = self::getData('chr'); |
||
414 | } |
||
415 | |||
416 | 7 | $chr = self::$CHR[$code_point]; |
|
417 | |||
418 | 7 | if ($encoding !== 'UTF-8') { |
|
419 | 1 | $chr = \mb_convert_encoding($chr, $encoding, 'UTF-8'); |
|
420 | } |
||
421 | |||
422 | 7 | return $CHAR_CACHE[$cacheKey] = $chr; |
|
423 | } |
||
424 | |||
425 | 7 | if (self::$SUPPORT['intlChar'] === true) { |
|
426 | 7 | $chr = \IntlChar::chr($code_point); |
|
427 | |||
428 | 7 | if ($encoding !== 'UTF-8') { |
|
429 | $chr = \mb_convert_encoding($chr, $encoding, 'UTF-8'); |
||
430 | } |
||
431 | |||
432 | 7 | return $CHAR_CACHE[$cacheKey] = $chr; |
|
433 | } |
||
434 | |||
435 | if (self::$CHR === null) { |
||
436 | self::$CHR = self::getData('chr'); |
||
437 | } |
||
438 | |||
439 | if ($code_point <= 0x7F) { |
||
440 | $chr = self::$CHR[$code_point]; |
||
441 | } elseif ($code_point <= 0x7FF) { |
||
442 | $chr = self::$CHR[($code_point >> 6) + 0xC0] . |
||
443 | self::$CHR[($code_point & 0x3F) + 0x80]; |
||
444 | } elseif ($code_point <= 0xFFFF) { |
||
445 | $chr = self::$CHR[($code_point >> 12) + 0xE0] . |
||
446 | self::$CHR[(($code_point >> 6) & 0x3F) + 0x80] . |
||
447 | self::$CHR[($code_point & 0x3F) + 0x80]; |
||
448 | } else { |
||
449 | $chr = self::$CHR[($code_point >> 18) + 0xF0] . |
||
450 | self::$CHR[(($code_point >> 12) & 0x3F) + 0x80] . |
||
451 | self::$CHR[(($code_point >> 6) & 0x3F) + 0x80] . |
||
452 | self::$CHR[($code_point & 0x3F) + 0x80]; |
||
453 | } |
||
454 | |||
455 | if ($encoding !== 'UTF-8') { |
||
456 | $chr = \mb_convert_encoding($chr, $encoding, 'UTF-8'); |
||
457 | } |
||
458 | |||
459 | return $CHAR_CACHE[$cacheKey] = $chr; |
||
460 | } |
||
461 | |||
462 | /** |
||
463 | * Applies callback to all characters of a string. |
||
464 | * |
||
465 | * @param string|array $callback <p>The callback function.</p> |
||
466 | * @param string $str <p>UTF-8 string to run callback on.</p> |
||
467 | * |
||
468 | * @return array <p>The outcome of callback.</p> |
||
469 | */ |
||
470 | 1 | public static function chr_map($callback, string $str): array |
|
471 | { |
||
472 | 1 | $chars = self::split($str); |
|
473 | |||
474 | 1 | return \array_map($callback, $chars); |
|
475 | } |
||
476 | |||
477 | /** |
||
478 | * Generates an array of byte length of each character of a Unicode string. |
||
479 | * |
||
480 | * 1 byte => U+0000 - U+007F |
||
481 | * 2 byte => U+0080 - U+07FF |
||
482 | * 3 byte => U+0800 - U+FFFF |
||
483 | * 4 byte => U+10000 - U+10FFFF |
||
484 | * |
||
485 | * @param string $str <p>The original unicode string.</p> |
||
486 | * |
||
487 | * @return array <p>An array of byte lengths of each character.</p> |
||
488 | */ |
||
489 | 2 | public static function chr_size_list(string $str): array |
|
490 | { |
||
491 | 2 | if (!isset($str[0])) { |
|
492 | 2 | return []; |
|
493 | } |
||
494 | |||
495 | 2 | $strSplit = self::split($str); |
|
496 | |||
497 | 2 | if (self::$SUPPORT['mbstring_func_overload'] === true) { |
|
498 | return \array_map( |
||
499 | function ($data) { |
||
500 | return UTF8::strlen($data, 'CP850'); // 8-BIT |
||
501 | }, |
||
502 | $strSplit |
||
503 | ); |
||
504 | } |
||
505 | |||
506 | 2 | return \array_map( |
|
507 | 2 | function ($data) { |
|
508 | 2 | return \strlen($data); |
|
509 | 2 | }, |
|
510 | 2 | $strSplit |
|
511 | ); |
||
512 | } |
||
513 | |||
514 | /** |
||
515 | * Get a decimal code representation of a specific character. |
||
516 | * |
||
517 | * @param string $char <p>The input character.</p> |
||
518 | * |
||
519 | * @return int |
||
520 | */ |
||
521 | 2 | public static function chr_to_decimal(string $char): int |
|
522 | { |
||
523 | 2 | $code = self::ord($char[0]); |
|
524 | 2 | $bytes = 1; |
|
525 | |||
526 | 2 | if (!($code & 0x80)) { |
|
527 | // 0xxxxxxx |
||
528 | 2 | return $code; |
|
529 | } |
||
530 | |||
531 | 2 | if (($code & 0xe0) === 0xc0) { |
|
532 | // 110xxxxx |
||
533 | 2 | $bytes = 2; |
|
534 | 2 | $code &= ~0xc0; |
|
535 | 2 | } elseif (($code & 0xf0) === 0xe0) { |
|
536 | // 1110xxxx |
||
537 | 2 | $bytes = 3; |
|
538 | 2 | $code &= ~0xe0; |
|
539 | 1 | } elseif (($code & 0xf8) === 0xf0) { |
|
540 | // 11110xxx |
||
541 | 1 | $bytes = 4; |
|
542 | 1 | $code &= ~0xf0; |
|
543 | } |
||
544 | |||
545 | 2 | for ($i = 2; $i <= $bytes; $i++) { |
|
546 | // 10xxxxxx |
||
547 | 2 | $code = ($code << 6) + (self::ord($char[$i - 1]) & ~0x80); |
|
548 | } |
||
549 | |||
550 | 2 | return $code; |
|
551 | } |
||
552 | |||
553 | /** |
||
554 | * Get hexadecimal code point (U+xxxx) of a UTF-8 encoded character. |
||
555 | * |
||
556 | * @param string $char <p>The input character</p> |
||
557 | * @param string $pfix [optional] |
||
558 | * |
||
559 | * @return string <p>The code point encoded as U+xxxx<p> |
||
560 | */ |
||
561 | 1 | public static function chr_to_hex(string $char, string $pfix = 'U+'): string |
|
562 | { |
||
563 | 1 | if (!isset($char[0])) { |
|
564 | 1 | return ''; |
|
565 | } |
||
566 | |||
567 | 1 | if ($char === '�') { |
|
568 | 1 | $char = ''; |
|
569 | } |
||
570 | |||
571 | 1 | return self::int_to_hex(self::ord($char), $pfix); |
|
572 | } |
||
573 | |||
574 | /** |
||
575 | * alias for "UTF8::chr_to_decimal()" |
||
576 | * |
||
577 | * @see UTF8::chr_to_decimal() |
||
578 | * |
||
579 | * @param string $chr |
||
580 | * |
||
581 | * @return int |
||
582 | */ |
||
583 | 1 | public static function chr_to_int(string $chr): int |
|
587 | |||
588 | /** |
||
589 | * Splits a string into smaller chunks and multiple lines, using the specified line ending character. |
||
590 | * |
||
591 | * @param string $body <p>The original string to be split.</p> |
||
592 | * @param int $chunklen [optional] <p>The maximum character length of a chunk.</p> |
||
593 | * @param string $end [optional] <p>The character(s) to be inserted at the end of each chunk.</p> |
||
594 | * |
||
595 | * @return string <p>The chunked string</p> |
||
596 | */ |
||
597 | 1 | public static function chunk_split(string $body, int $chunklen = 76, string $end = "\r\n"): string |
|
601 | |||
602 | /** |
||
603 | * Accepts a string and removes all non-UTF-8 characters from it + extras if needed. |
||
604 | * |
||
605 | * @param string $str <p>The string to be sanitized.</p> |
||
606 | * @param bool $remove_bom [optional] <p>Set to true, if you need to remove UTF-BOM.</p> |
||
607 | * @param bool $normalize_whitespace [optional] <p>Set to true, if you need to normalize the |
||
608 | * whitespace.</p> |
||
609 | * @param bool $normalize_msword [optional] <p>Set to true, if you need to normalize MS Word chars |
||
610 | * e.g.: "…" |
||
611 | * => "..."</p> |
||
612 | * @param bool $keep_non_breaking_space [optional] <p>Set to true, to keep non-breaking-spaces, in |
||
613 | * combination with |
||
614 | * $normalize_whitespace</p> |
||
615 | * @param bool $replace_diamond_question_mark [optional] <p>Set to true, if you need to remove diamond question |
||
616 | * mark e.g.: "�"</p> |
||
617 | * @param bool $remove_invisible_characters [optional] <p>Set to false, if you not want to remove invisible |
||
618 | * characters e.g.: "\0"</p> |
||
619 | * |
||
620 | * @return string <p>Clean UTF-8 encoded string.</p> |
||
621 | */ |
||
622 | 64 | public static function clean(string $str, bool $remove_bom = false, bool $normalize_whitespace = false, bool $normalize_msword = false, bool $keep_non_breaking_space = false, bool $replace_diamond_question_mark = false, bool $remove_invisible_characters = true): string |
|
662 | |||
663 | /** |
||
664 | * Clean-up a and show only printable UTF-8 chars at the end + fix UTF-8 encoding. |
||
665 | * |
||
666 | * @param string $str <p>The input string.</p> |
||
667 | * |
||
668 | * @return string |
||
669 | */ |
||
670 | 24 | public static function cleanup(string $str): string |
|
696 | |||
697 | /** |
||
698 | * Accepts a string or a array of strings and returns an array of Unicode code points. |
||
699 | * |
||
700 | * INFO: opposite to UTF8::string() |
||
701 | * |
||
702 | * @param string|string[] $arg <p>A UTF-8 encoded string or an array of such strings.</p> |
||
703 | * @param bool $u_style <p>If True, will return code points in U+xxxx format, |
||
704 | * default, code points will be returned as integers.</p> |
||
705 | * |
||
706 | * @return array <p>The array of code points.</p> |
||
707 | */ |
||
708 | 7 | public static function codepoints($arg, bool $u_style = false): array |
|
734 | |||
735 | /** |
||
736 | * Returns count of characters used in a string. |
||
737 | * |
||
738 | * @param string $str <p>The input string.</p> |
||
739 | * @param bool $cleanUtf8 [optional] <p>Remove non UTF-8 chars from the string.</p> |
||
740 | * |
||
741 | * @return array <p>An associative array of Character as keys and |
||
742 | * their count as values.</p> |
||
743 | */ |
||
744 | 9 | public static function count_chars(string $str, bool $cleanUtf8 = false): array |
|
748 | |||
749 | /** |
||
750 | * Converts a int-value into an UTF-8 character. |
||
751 | * |
||
752 | * @param mixed $int |
||
753 | * |
||
754 | * @return string |
||
755 | */ |
||
756 | 5 | public static function decimal_to_chr($int): string |
|
760 | |||
761 | /** |
||
762 | * Encode a string with a new charset-encoding. |
||
763 | * |
||
764 | * INFO: The different to "UTF8::utf8_encode()" is that this function, try to fix also broken / double encoding, |
||
765 | * so you can call this function also on a UTF-8 String and you don't mess the string. |
||
766 | * |
||
767 | * @param string $encoding <p>e.g. 'UTF-16', 'UTF-8', 'ISO-8859-1', etc.</p> |
||
768 | * @param string $str <p>The input string</p> |
||
769 | * @param bool $force [optional] <p>Force the new encoding (we try to fix broken / double encoding for |
||
770 | * UTF-8)<br> otherwise we auto-detect the current string-encoding</p> |
||
771 | * |
||
772 | * @return string |
||
773 | */ |
||
774 | 14 | public static function encode(string $encoding, string $str, bool $force = true): string |
|
847 | |||
848 | /** |
||
849 | * Reads entire file into a string. |
||
850 | * |
||
851 | * WARNING: do not use UTF-8 Option ($convertToUtf8) for binary-files (e.g.: images) !!! |
||
852 | * |
||
853 | * @link http://php.net/manual/en/function.file-get-contents.php |
||
854 | * |
||
855 | * @param string $filename <p> |
||
856 | * Name of the file to read. |
||
857 | * </p> |
||
858 | * @param bool $use_include_path [optional] <p> |
||
859 | * Prior to PHP 5, this parameter is called |
||
860 | * use_include_path and is a bool. |
||
861 | * As of PHP 5 the FILE_USE_INCLUDE_PATH can be used |
||
862 | * to trigger include path |
||
863 | * search. |
||
864 | * </p> |
||
865 | * @param resource|null $context [optional] <p> |
||
866 | * A valid context resource created with |
||
867 | * stream_context_create. If you don't need to use a |
||
868 | * custom context, you can skip this parameter by &null;. |
||
869 | * </p> |
||
870 | * @param int|null $offset [optional] <p> |
||
871 | * The offset where the reading starts. |
||
872 | * </p> |
||
873 | * @param int|null $maxLength [optional] <p> |
||
874 | * Maximum length of data read. The default is to read until end |
||
875 | * of file is reached. |
||
876 | * </p> |
||
877 | * @param int $timeout <p>The time in seconds for the timeout.</p> |
||
878 | * |
||
879 | * @param bool $convertToUtf8 <strong>WARNING!!!</strong> <p>Maybe you can't use this option for e.g. |
||
880 | * images or pdf, because they used non default utf-8 chars.</p> |
||
881 | * |
||
882 | * @return string|false <p>The function returns the read data or false on failure.</p> |
||
883 | */ |
||
884 | 6 | public static function file_get_contents(string $filename, bool $use_include_path = false, $context = null, int $offset = null, int $maxLength = null, int $timeout = 10, bool $convertToUtf8 = true) |
|
931 | |||
932 | /** |
||
933 | * Checks if a file starts with BOM (Byte Order Mark) character. |
||
934 | * |
||
935 | * @param string $file_path <p>Path to a valid file.</p> |
||
936 | * |
||
937 | * @return bool <p><strong>true</strong> if the file has BOM at the start, <strong>false</strong> otherwise.</> |
||
938 | */ |
||
939 | 1 | public static function file_has_bom(string $file_path): bool |
|
943 | |||
944 | /** |
||
945 | * Normalizes to UTF-8 NFC, converting from WINDOWS-1252 when needed. |
||
946 | * |
||
947 | * @param mixed $var |
||
948 | * @param int $normalization_form |
||
949 | * @param string $leading_combining |
||
950 | * |
||
951 | * @return mixed |
||
952 | */ |
||
953 | 9 | public static function filter($var, int $normalization_form = 4 /* n::NFC */, string $leading_combining = '◌') |
|
1007 | |||
1008 | /** |
||
1009 | * "filter_input()"-wrapper with normalizes to UTF-8 NFC, converting from WINDOWS-1252 when needed. |
||
1010 | * |
||
1011 | * Gets a specific external variable by name and optionally filters it |
||
1012 | * |
||
1013 | * @link http://php.net/manual/en/function.filter-input.php |
||
1014 | * |
||
1015 | * @param int $type <p> |
||
1016 | * One of <b>INPUT_GET</b>, <b>INPUT_POST</b>, |
||
1017 | * <b>INPUT_COOKIE</b>, <b>INPUT_SERVER</b>, or |
||
1018 | * <b>INPUT_ENV</b>. |
||
1019 | * </p> |
||
1020 | * @param string $variable_name <p> |
||
1021 | * Name of a variable to get. |
||
1022 | * </p> |
||
1023 | * @param int $filter [optional] <p> |
||
1024 | * The ID of the filter to apply. The |
||
1025 | * manual page lists the available filters. |
||
1026 | * </p> |
||
1027 | * @param mixed $options [optional] <p> |
||
1028 | * Associative array of options or bitwise disjunction of flags. If filter |
||
1029 | * accepts options, flags can be provided in "flags" field of array. |
||
1030 | * </p> |
||
1031 | * |
||
1032 | * @return mixed Value of the requested variable on success, <b>FALSE</b> if the filter fails, |
||
1033 | * or <b>NULL</b> if the <i>variable_name</i> variable is not set. |
||
1034 | * If the flag <b>FILTER_NULL_ON_FAILURE</b> is used, it |
||
1035 | * returns <b>FALSE</b> if the variable is not set and <b>NULL</b> if the filter fails. |
||
1036 | * @since 5.2.0 |
||
1037 | */ |
||
1038 | View Code Duplication | public static function filter_input(int $type, string $variable_name, int $filter = FILTER_DEFAULT, $options = null) |
|
1048 | |||
1049 | /** |
||
1050 | * "filter_input_array()"-wrapper with normalizes to UTF-8 NFC, converting from WINDOWS-1252 when needed. |
||
1051 | * |
||
1052 | * Gets external variables and optionally filters them |
||
1053 | * |
||
1054 | * @link http://php.net/manual/en/function.filter-input-array.php |
||
1055 | * |
||
1056 | * @param int $type <p> |
||
1057 | * One of <b>INPUT_GET</b>, <b>INPUT_POST</b>, |
||
1058 | * <b>INPUT_COOKIE</b>, <b>INPUT_SERVER</b>, or |
||
1059 | * <b>INPUT_ENV</b>. |
||
1060 | * </p> |
||
1061 | * @param mixed $definition [optional] <p> |
||
1062 | * An array defining the arguments. A valid key is a string |
||
1063 | * containing a variable name and a valid value is either a filter type, or an array |
||
1064 | * optionally specifying the filter, flags and options. If the value is an |
||
1065 | * array, valid keys are filter which specifies the |
||
1066 | * filter type, |
||
1067 | * flags which specifies any flags that apply to the |
||
1068 | * filter, and options which specifies any options that |
||
1069 | * apply to the filter. See the example below for a better understanding. |
||
1070 | * </p> |
||
1071 | * <p> |
||
1072 | * This parameter can be also an integer holding a filter constant. Then all values in the |
||
1073 | * input array are filtered by this filter. |
||
1074 | * </p> |
||
1075 | * @param bool $add_empty [optional] <p> |
||
1076 | * Add missing keys as <b>NULL</b> to the return value. |
||
1077 | * </p> |
||
1078 | * |
||
1079 | * @return mixed An array containing the values of the requested variables on success, or <b>FALSE</b> |
||
1080 | * on failure. An array value will be <b>FALSE</b> if the filter fails, or <b>NULL</b> if |
||
1081 | * the variable is not set. Or if the flag <b>FILTER_NULL_ON_FAILURE</b> |
||
1082 | * is used, it returns <b>FALSE</b> if the variable is not set and <b>NULL</b> if the filter |
||
1083 | * fails. |
||
1084 | * @since 5.2.0 |
||
1085 | */ |
||
1086 | View Code Duplication | public static function filter_input_array(int $type, $definition = null, bool $add_empty = true) |
|
1096 | |||
1097 | /** |
||
1098 | * "filter_var()"-wrapper with normalizes to UTF-8 NFC, converting from WINDOWS-1252 when needed. |
||
1099 | * |
||
1100 | * Filters a variable with a specified filter |
||
1101 | * |
||
1102 | * @link http://php.net/manual/en/function.filter-var.php |
||
1103 | * |
||
1104 | * @param mixed $variable <p> |
||
1105 | * Value to filter. |
||
1106 | * </p> |
||
1107 | * @param int $filter [optional] <p> |
||
1108 | * The ID of the filter to apply. The |
||
1109 | * manual page lists the available filters. |
||
1110 | * </p> |
||
1111 | * @param mixed $options [optional] <p> |
||
1112 | * Associative array of options or bitwise disjunction of flags. If filter |
||
1113 | * accepts options, flags can be provided in "flags" field of array. For |
||
1114 | * the "callback" filter, callable type should be passed. The |
||
1115 | * callback must accept one argument, the value to be filtered, and return |
||
1116 | * the value after filtering/sanitizing it. |
||
1117 | * </p> |
||
1118 | * <p> |
||
1119 | * <code> |
||
1120 | * // for filters that accept options, use this format |
||
1121 | * $options = array( |
||
1122 | * 'options' => array( |
||
1123 | * 'default' => 3, // value to return if the filter fails |
||
1124 | * // other options here |
||
1125 | * 'min_range' => 0 |
||
1126 | * ), |
||
1127 | * 'flags' => FILTER_FLAG_ALLOW_OCTAL, |
||
1128 | * ); |
||
1129 | * $var = filter_var('0755', FILTER_VALIDATE_INT, $options); |
||
1130 | * // for filter that only accept flags, you can pass them directly |
||
1131 | * $var = filter_var('oops', FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE); |
||
1132 | * // for filter that only accept flags, you can also pass as an array |
||
1133 | * $var = filter_var('oops', FILTER_VALIDATE_BOOLEAN, |
||
1134 | * array('flags' => FILTER_NULL_ON_FAILURE)); |
||
1135 | * // callback validate filter |
||
1136 | * function foo($value) |
||
1137 | * { |
||
1138 | * // Expected format: Surname, GivenNames |
||
1139 | * if (strpos($value, ", ") === false) return false; |
||
1140 | * list($surname, $givennames) = explode(", ", $value, 2); |
||
1141 | * $empty = (empty($surname) || empty($givennames)); |
||
1142 | * $notstrings = (!is_string($surname) || !is_string($givennames)); |
||
1143 | * if ($empty || $notstrings) { |
||
1144 | * return false; |
||
1145 | * } else { |
||
1146 | * return $value; |
||
1147 | * } |
||
1148 | * } |
||
1149 | * $var = filter_var('Doe, Jane Sue', FILTER_CALLBACK, array('options' => 'foo')); |
||
1150 | * </code> |
||
1151 | * </p> |
||
1152 | * |
||
1153 | * @return mixed the filtered data, or <b>FALSE</b> if the filter fails. |
||
1154 | * @since 5.2.0 |
||
1155 | */ |
||
1156 | 1 | View Code Duplication | public static function filter_var($variable, int $filter = FILTER_DEFAULT, $options = null) |
1166 | |||
1167 | /** |
||
1168 | * "filter_var_array()"-wrapper with normalizes to UTF-8 NFC, converting from WINDOWS-1252 when needed. |
||
1169 | * |
||
1170 | * Gets multiple variables and optionally filters them |
||
1171 | * |
||
1172 | * @link http://php.net/manual/en/function.filter-var-array.php |
||
1173 | * |
||
1174 | * @param array $data <p> |
||
1175 | * An array with string keys containing the data to filter. |
||
1176 | * </p> |
||
1177 | * @param mixed $definition [optional] <p> |
||
1178 | * An array defining the arguments. A valid key is a string |
||
1179 | * containing a variable name and a valid value is either a |
||
1180 | * filter type, or an |
||
1181 | * array optionally specifying the filter, flags and options. |
||
1182 | * If the value is an array, valid keys are filter |
||
1183 | * which specifies the filter type, |
||
1184 | * flags which specifies any flags that apply to the |
||
1185 | * filter, and options which specifies any options that |
||
1186 | * apply to the filter. See the example below for a better understanding. |
||
1187 | * </p> |
||
1188 | * <p> |
||
1189 | * This parameter can be also an integer holding a filter constant. Then all values in the |
||
1190 | * input array are filtered by this filter. |
||
1191 | * </p> |
||
1192 | * @param bool $add_empty [optional] <p> |
||
1193 | * Add missing keys as <b>NULL</b> to the return value. |
||
1194 | * </p> |
||
1195 | * |
||
1196 | * @return mixed An array containing the values of the requested variables on success, or <b>FALSE</b> |
||
1197 | * on failure. An array value will be <b>FALSE</b> if the filter fails, or <b>NULL</b> if |
||
1198 | * the variable is not set. |
||
1199 | * @since 5.2.0 |
||
1200 | */ |
||
1201 | 1 | View Code Duplication | public static function filter_var_array(array $data, $definition = null, bool $add_empty = true) |
1211 | |||
1212 | /** |
||
1213 | * Check if the number of unicode characters are not more than the specified integer. |
||
1214 | * |
||
1215 | * @param string $str The original string to be checked. |
||
1216 | * @param int $box_size The size in number of chars to be checked against string. |
||
1217 | * |
||
1218 | * @return bool true if string is less than or equal to $box_size, false otherwise. |
||
1219 | */ |
||
1220 | 1 | public static function fits_inside(string $str, int $box_size): bool |
|
1224 | |||
1225 | /** |
||
1226 | * Try to fix simple broken UTF-8 strings. |
||
1227 | * |
||
1228 | * INFO: Take a look at "UTF8::fix_utf8()" if you need a more advanced fix for broken UTF-8 strings. |
||
1229 | * |
||
1230 | * If you received an UTF-8 string that was converted from Windows-1252 as it was ISO-8859-1 |
||
1231 | * (ignoring Windows-1252 chars from 80 to 9F) use this function to fix it. |
||
1232 | * See: http://en.wikipedia.org/wiki/Windows-1252 |
||
1233 | * |
||
1234 | * @param string $str <p>The input string</p> |
||
1235 | * |
||
1236 | * @return string |
||
1237 | */ |
||
1238 | 29 | View Code Duplication | public static function fix_simple_utf8(string $str): string |
1259 | |||
1260 | /** |
||
1261 | * Fix a double (or multiple) encoded UTF8 string. |
||
1262 | * |
||
1263 | * @param string|string[] $str <p>You can use a string or an array of strings.</p> |
||
1264 | * |
||
1265 | * @return string|string[] <p>Will return the fixed input-"array" or |
||
1266 | * the fixed input-"string".</p> |
||
1267 | */ |
||
1268 | 1 | public static function fix_utf8($str) |
|
1288 | |||
1289 | /** |
||
1290 | * Get character of a specific character. |
||
1291 | * |
||
1292 | * @param string $char |
||
1293 | * |
||
1294 | * @return string <p>'RTL' or 'LTR'</p> |
||
1295 | */ |
||
1296 | 1 | public static function getCharDirection(string $char): string |
|
1410 | |||
1411 | /** |
||
1412 | * get data from "/data/*.ser" |
||
1413 | * |
||
1414 | * @param string $file |
||
1415 | * |
||
1416 | * @return bool|string|array|int <p>Will return false on error.</p> |
||
1417 | */ |
||
1418 | 7 | private static function getData(string $file) |
|
1428 | |||
1429 | /** |
||
1430 | * Check for php-support. |
||
1431 | * |
||
1432 | * @param string|null $key |
||
1433 | * |
||
1434 | * @return mixed <p>Return the full support-"array", if $key === null<br> |
||
1435 | * return bool-value, if $key is used and available<br> |
||
1436 | * otherwise return null</p> |
||
1437 | */ |
||
1438 | 19 | public static function getSupportInfo(string $key = null) |
|
1454 | |||
1455 | /** |
||
1456 | * alias for "UTF8::string_has_bom()" |
||
1457 | * |
||
1458 | * @see UTF8::string_has_bom() |
||
1459 | * |
||
1460 | * @param string $str |
||
1461 | * |
||
1462 | * @return bool |
||
1463 | * |
||
1464 | * @deprecated <p>use "UTF8::string_has_bom()"</p> |
||
1465 | */ |
||
1466 | 1 | public static function hasBom(string $str): bool |
|
1470 | |||
1471 | /** |
||
1472 | * Converts a hexadecimal-value into an UTF-8 character. |
||
1473 | * |
||
1474 | * @param string $hexdec <p>The hexadecimal value.</p> |
||
1475 | * |
||
1476 | * @return string|false <p>One single UTF-8 character.</p> |
||
1477 | */ |
||
1478 | 2 | public static function hex_to_chr(string $hexdec) |
|
1482 | |||
1483 | /** |
||
1484 | * Converts hexadecimal U+xxxx code point representation to integer. |
||
1485 | * |
||
1486 | * INFO: opposite to UTF8::int_to_hex() |
||
1487 | * |
||
1488 | * @param string $hexDec <p>The hexadecimal code point representation.</p> |
||
1489 | * |
||
1490 | * @return int|false <p>The code point, or false on failure.</p> |
||
1491 | */ |
||
1492 | 1 | public static function hex_to_int(string $hexDec) |
|
1504 | |||
1505 | /** |
||
1506 | * alias for "UTF8::html_entity_decode()" |
||
1507 | * |
||
1508 | * @see UTF8::html_entity_decode() |
||
1509 | * |
||
1510 | * @param string $str |
||
1511 | * @param int $flags |
||
1512 | * @param string $encoding |
||
1513 | * |
||
1514 | * @return string |
||
1515 | */ |
||
1516 | 1 | public static function html_decode(string $str, int $flags = null, string $encoding = 'UTF-8'): string |
|
1520 | |||
1521 | /** |
||
1522 | * Converts a UTF-8 string to a series of HTML numbered entities. |
||
1523 | * |
||
1524 | * INFO: opposite to UTF8::html_decode() |
||
1525 | * |
||
1526 | * @param string $str <p>The Unicode string to be encoded as numbered entities.</p> |
||
1527 | * @param bool $keepAsciiChars [optional] <p>Keep ASCII chars.</p> |
||
1528 | * @param string $encoding [optional] <p>Default is UTF-8</p> |
||
1529 | * |
||
1530 | * @return string <p>HTML numbered entities.</p> |
||
1531 | */ |
||
1532 | 3 | public static function html_encode(string $str, bool $keepAsciiChars = false, string $encoding = 'UTF-8'): string |
|
1567 | |||
1568 | /** |
||
1569 | * UTF-8 version of html_entity_decode() |
||
1570 | * |
||
1571 | * The reason we are not using html_entity_decode() by itself is because |
||
1572 | * while it is not technically correct to leave out the semicolon |
||
1573 | * at the end of an entity most browsers will still interpret the entity |
||
1574 | * correctly. html_entity_decode() does not convert entities without |
||
1575 | * semicolons, so we are left with our own little solution here. Bummer. |
||
1576 | * |
||
1577 | * Convert all HTML entities to their applicable characters |
||
1578 | * |
||
1579 | * INFO: opposite to UTF8::html_encode() |
||
1580 | * |
||
1581 | * @link http://php.net/manual/en/function.html-entity-decode.php |
||
1582 | * |
||
1583 | * @param string $str <p> |
||
1584 | * The input string. |
||
1585 | * </p> |
||
1586 | * @param int $flags [optional] <p> |
||
1587 | * A bitmask of one or more of the following flags, which specify how to handle quotes and |
||
1588 | * which document type to use. The default is ENT_COMPAT | ENT_HTML401. |
||
1589 | * <table> |
||
1590 | * Available <i>flags</i> constants |
||
1591 | * <tr valign="top"> |
||
1592 | * <td>Constant Name</td> |
||
1593 | * <td>Description</td> |
||
1594 | * </tr> |
||
1595 | * <tr valign="top"> |
||
1596 | * <td><b>ENT_COMPAT</b></td> |
||
1597 | * <td>Will convert double-quotes and leave single-quotes alone.</td> |
||
1598 | * </tr> |
||
1599 | * <tr valign="top"> |
||
1600 | * <td><b>ENT_QUOTES</b></td> |
||
1601 | * <td>Will convert both double and single quotes.</td> |
||
1602 | * </tr> |
||
1603 | * <tr valign="top"> |
||
1604 | * <td><b>ENT_NOQUOTES</b></td> |
||
1605 | * <td>Will leave both double and single quotes unconverted.</td> |
||
1606 | * </tr> |
||
1607 | * <tr valign="top"> |
||
1608 | * <td><b>ENT_HTML401</b></td> |
||
1609 | * <td> |
||
1610 | * Handle code as HTML 4.01. |
||
1611 | * </td> |
||
1612 | * </tr> |
||
1613 | * <tr valign="top"> |
||
1614 | * <td><b>ENT_XML1</b></td> |
||
1615 | * <td> |
||
1616 | * Handle code as XML 1. |
||
1617 | * </td> |
||
1618 | * </tr> |
||
1619 | * <tr valign="top"> |
||
1620 | * <td><b>ENT_XHTML</b></td> |
||
1621 | * <td> |
||
1622 | * Handle code as XHTML. |
||
1623 | * </td> |
||
1624 | * </tr> |
||
1625 | * <tr valign="top"> |
||
1626 | * <td><b>ENT_HTML5</b></td> |
||
1627 | * <td> |
||
1628 | * Handle code as HTML 5. |
||
1629 | * </td> |
||
1630 | * </tr> |
||
1631 | * </table> |
||
1632 | * </p> |
||
1633 | * @param string $encoding [optional] <p>Encoding to use.</p> |
||
1634 | * |
||
1635 | * @return string <p>The decoded string.</p> |
||
1636 | */ |
||
1637 | 17 | public static function html_entity_decode(string $str, int $flags = null, string $encoding = 'UTF-8'): string |
|
1707 | |||
1708 | /** |
||
1709 | * Convert all applicable characters to HTML entities: UTF-8 version of htmlentities() |
||
1710 | * |
||
1711 | * @link http://php.net/manual/en/function.htmlentities.php |
||
1712 | * |
||
1713 | * @param string $str <p> |
||
1714 | * The input string. |
||
1715 | * </p> |
||
1716 | * @param int $flags [optional] <p> |
||
1717 | * A bitmask of one or more of the following flags, which specify how to handle quotes, |
||
1718 | * invalid code unit sequences and the used document type. The default is |
||
1719 | * ENT_COMPAT | ENT_HTML401. |
||
1720 | * <table> |
||
1721 | * Available <i>flags</i> constants |
||
1722 | * <tr valign="top"> |
||
1723 | * <td>Constant Name</td> |
||
1724 | * <td>Description</td> |
||
1725 | * </tr> |
||
1726 | * <tr valign="top"> |
||
1727 | * <td><b>ENT_COMPAT</b></td> |
||
1728 | * <td>Will convert double-quotes and leave single-quotes alone.</td> |
||
1729 | * </tr> |
||
1730 | * <tr valign="top"> |
||
1731 | * <td><b>ENT_QUOTES</b></td> |
||
1732 | * <td>Will convert both double and single quotes.</td> |
||
1733 | * </tr> |
||
1734 | * <tr valign="top"> |
||
1735 | * <td><b>ENT_NOQUOTES</b></td> |
||
1736 | * <td>Will leave both double and single quotes unconverted.</td> |
||
1737 | * </tr> |
||
1738 | * <tr valign="top"> |
||
1739 | * <td><b>ENT_IGNORE</b></td> |
||
1740 | * <td> |
||
1741 | * Silently discard invalid code unit sequences instead of returning |
||
1742 | * an empty string. Using this flag is discouraged as it |
||
1743 | * may have security implications. |
||
1744 | * </td> |
||
1745 | * </tr> |
||
1746 | * <tr valign="top"> |
||
1747 | * <td><b>ENT_SUBSTITUTE</b></td> |
||
1748 | * <td> |
||
1749 | * Replace invalid code unit sequences with a Unicode Replacement Character |
||
1750 | * U+FFFD (UTF-8) or &#38;#FFFD; (otherwise) instead of returning an empty string. |
||
1751 | * </td> |
||
1752 | * </tr> |
||
1753 | * <tr valign="top"> |
||
1754 | * <td><b>ENT_DISALLOWED</b></td> |
||
1755 | * <td> |
||
1756 | * Replace invalid code points for the given document type with a |
||
1757 | * Unicode Replacement Character U+FFFD (UTF-8) or &#38;#FFFD; |
||
1758 | * (otherwise) instead of leaving them as is. This may be useful, for |
||
1759 | * instance, to ensure the well-formedness of XML documents with |
||
1760 | * embedded external content. |
||
1761 | * </td> |
||
1762 | * </tr> |
||
1763 | * <tr valign="top"> |
||
1764 | * <td><b>ENT_HTML401</b></td> |
||
1765 | * <td> |
||
1766 | * Handle code as HTML 4.01. |
||
1767 | * </td> |
||
1768 | * </tr> |
||
1769 | * <tr valign="top"> |
||
1770 | * <td><b>ENT_XML1</b></td> |
||
1771 | * <td> |
||
1772 | * Handle code as XML 1. |
||
1773 | * </td> |
||
1774 | * </tr> |
||
1775 | * <tr valign="top"> |
||
1776 | * <td><b>ENT_XHTML</b></td> |
||
1777 | * <td> |
||
1778 | * Handle code as XHTML. |
||
1779 | * </td> |
||
1780 | * </tr> |
||
1781 | * <tr valign="top"> |
||
1782 | * <td><b>ENT_HTML5</b></td> |
||
1783 | * <td> |
||
1784 | * Handle code as HTML 5. |
||
1785 | * </td> |
||
1786 | * </tr> |
||
1787 | * </table> |
||
1788 | * </p> |
||
1789 | * @param string $encoding [optional] <p> |
||
1790 | * Like <b>htmlspecialchars</b>, |
||
1791 | * <b>htmlentities</b> takes an optional third argument |
||
1792 | * <i>encoding</i> which defines encoding used in |
||
1793 | * conversion. |
||
1794 | * Although this argument is technically optional, you are highly |
||
1795 | * encouraged to specify the correct value for your code. |
||
1796 | * </p> |
||
1797 | * @param bool $double_encode [optional] <p> |
||
1798 | * When <i>double_encode</i> is turned off PHP will not |
||
1799 | * encode existing html entities. The default is to convert everything. |
||
1800 | * </p> |
||
1801 | * |
||
1802 | * |
||
1803 | * @return string the encoded string. |
||
1804 | * </p> |
||
1805 | * <p> |
||
1806 | * If the input <i>string</i> contains an invalid code unit |
||
1807 | * sequence within the given <i>encoding</i> an empty string |
||
1808 | * will be returned, unless either the <b>ENT_IGNORE</b> or |
||
1809 | * <b>ENT_SUBSTITUTE</b> flags are set. |
||
1810 | */ |
||
1811 | 2 | public static function htmlentities(string $str, int $flags = ENT_COMPAT, string $encoding = 'UTF-8', bool $double_encode = true): string |
|
1831 | |||
1832 | /** |
||
1833 | * Convert only special characters to HTML entities: UTF-8 version of htmlspecialchars() |
||
1834 | * |
||
1835 | * INFO: Take a look at "UTF8::htmlentities()" |
||
1836 | * |
||
1837 | * @link http://php.net/manual/en/function.htmlspecialchars.php |
||
1838 | * |
||
1839 | * @param string $str <p> |
||
1840 | * The string being converted. |
||
1841 | * </p> |
||
1842 | * @param int $flags [optional] <p> |
||
1843 | * A bitmask of one or more of the following flags, which specify how to handle quotes, |
||
1844 | * invalid code unit sequences and the used document type. The default is |
||
1845 | * ENT_COMPAT | ENT_HTML401. |
||
1846 | * <table> |
||
1847 | * Available <i>flags</i> constants |
||
1848 | * <tr valign="top"> |
||
1849 | * <td>Constant Name</td> |
||
1850 | * <td>Description</td> |
||
1851 | * </tr> |
||
1852 | * <tr valign="top"> |
||
1853 | * <td><b>ENT_COMPAT</b></td> |
||
1854 | * <td>Will convert double-quotes and leave single-quotes alone.</td> |
||
1855 | * </tr> |
||
1856 | * <tr valign="top"> |
||
1857 | * <td><b>ENT_QUOTES</b></td> |
||
1858 | * <td>Will convert both double and single quotes.</td> |
||
1859 | * </tr> |
||
1860 | * <tr valign="top"> |
||
1861 | * <td><b>ENT_NOQUOTES</b></td> |
||
1862 | * <td>Will leave both double and single quotes unconverted.</td> |
||
1863 | * </tr> |
||
1864 | * <tr valign="top"> |
||
1865 | * <td><b>ENT_IGNORE</b></td> |
||
1866 | * <td> |
||
1867 | * Silently discard invalid code unit sequences instead of returning |
||
1868 | * an empty string. Using this flag is discouraged as it |
||
1869 | * may have security implications. |
||
1870 | * </td> |
||
1871 | * </tr> |
||
1872 | * <tr valign="top"> |
||
1873 | * <td><b>ENT_SUBSTITUTE</b></td> |
||
1874 | * <td> |
||
1875 | * Replace invalid code unit sequences with a Unicode Replacement Character |
||
1876 | * U+FFFD (UTF-8) or &#38;#FFFD; (otherwise) instead of returning an empty string. |
||
1877 | * </td> |
||
1878 | * </tr> |
||
1879 | * <tr valign="top"> |
||
1880 | * <td><b>ENT_DISALLOWED</b></td> |
||
1881 | * <td> |
||
1882 | * Replace invalid code points for the given document type with a |
||
1883 | * Unicode Replacement Character U+FFFD (UTF-8) or &#38;#FFFD; |
||
1884 | * (otherwise) instead of leaving them as is. This may be useful, for |
||
1885 | * instance, to ensure the well-formedness of XML documents with |
||
1886 | * embedded external content. |
||
1887 | * </td> |
||
1888 | * </tr> |
||
1889 | * <tr valign="top"> |
||
1890 | * <td><b>ENT_HTML401</b></td> |
||
1891 | * <td> |
||
1892 | * Handle code as HTML 4.01. |
||
1893 | * </td> |
||
1894 | * </tr> |
||
1895 | * <tr valign="top"> |
||
1896 | * <td><b>ENT_XML1</b></td> |
||
1897 | * <td> |
||
1898 | * Handle code as XML 1. |
||
1899 | * </td> |
||
1900 | * </tr> |
||
1901 | * <tr valign="top"> |
||
1902 | * <td><b>ENT_XHTML</b></td> |
||
1903 | * <td> |
||
1904 | * Handle code as XHTML. |
||
1905 | * </td> |
||
1906 | * </tr> |
||
1907 | * <tr valign="top"> |
||
1908 | * <td><b>ENT_HTML5</b></td> |
||
1909 | * <td> |
||
1910 | * Handle code as HTML 5. |
||
1911 | * </td> |
||
1912 | * </tr> |
||
1913 | * </table> |
||
1914 | * </p> |
||
1915 | * @param string $encoding [optional] <p> |
||
1916 | * Defines encoding used in conversion. |
||
1917 | * </p> |
||
1918 | * <p> |
||
1919 | * For the purposes of this function, the encodings |
||
1920 | * ISO-8859-1, ISO-8859-15, |
||
1921 | * UTF-8, cp866, |
||
1922 | * cp1251, cp1252, and |
||
1923 | * KOI8-R are effectively equivalent, provided the |
||
1924 | * <i>string</i> itself is valid for the encoding, as |
||
1925 | * the characters affected by <b>htmlspecialchars</b> occupy |
||
1926 | * the same positions in all of these encodings. |
||
1927 | * </p> |
||
1928 | * @param bool $double_encode [optional] <p> |
||
1929 | * When <i>double_encode</i> is turned off PHP will not |
||
1930 | * encode existing html entities, the default is to convert everything. |
||
1931 | * </p> |
||
1932 | * |
||
1933 | * @return string The converted string. |
||
1934 | * </p> |
||
1935 | * <p> |
||
1936 | * If the input <i>string</i> contains an invalid code unit |
||
1937 | * sequence within the given <i>encoding</i> an empty string |
||
1938 | * will be returned, unless either the <b>ENT_IGNORE</b> or |
||
1939 | * <b>ENT_SUBSTITUTE</b> flags are set. |
||
1940 | */ |
||
1941 | 1 | View Code Duplication | public static function htmlspecialchars(string $str, int $flags = ENT_COMPAT, string $encoding = 'UTF-8', bool $double_encode = true): string |
1949 | |||
1950 | /** |
||
1951 | * Checks whether iconv is available on the server. |
||
1952 | * |
||
1953 | * @return bool <p><strong>true</strong> if available, <strong>false</strong> otherwise.</p> |
||
1954 | */ |
||
1955 | 1 | public static function iconv_loaded(): bool |
|
1959 | |||
1960 | /** |
||
1961 | * alias for "UTF8::decimal_to_chr()" |
||
1962 | * |
||
1963 | * @see UTF8::decimal_to_chr() |
||
1964 | * |
||
1965 | * @param mixed $int |
||
1966 | * |
||
1967 | * @return string |
||
1968 | */ |
||
1969 | 2 | public static function int_to_chr($int): string |
|
1973 | |||
1974 | /** |
||
1975 | * Converts Integer to hexadecimal U+xxxx code point representation. |
||
1976 | * |
||
1977 | * INFO: opposite to UTF8::hex_to_int() |
||
1978 | * |
||
1979 | * @param int $int <p>The integer to be converted to hexadecimal code point.</p> |
||
1980 | * @param string $pfix [optional] |
||
1981 | * |
||
1982 | * @return string <p>The code point, or empty string on failure.</p> |
||
1983 | */ |
||
1984 | 3 | public static function int_to_hex(int $int, string $pfix = 'U+'): string |
|
1992 | |||
1993 | /** |
||
1994 | * Checks whether intl-char is available on the server. |
||
1995 | * |
||
1996 | * @return bool <p><strong>true</strong> if available, <strong>false</strong> otherwise.</p> |
||
1997 | */ |
||
1998 | 1 | public static function intlChar_loaded(): bool |
|
2002 | |||
2003 | /** |
||
2004 | * Checks whether intl is available on the server. |
||
2005 | * |
||
2006 | * @return bool <p><strong>true</strong> if available, <strong>false</strong> otherwise.</p> |
||
2007 | */ |
||
2008 | 4 | public static function intl_loaded(): bool |
|
2012 | |||
2013 | /** |
||
2014 | * alias for "UTF8::is_ascii()" |
||
2015 | * |
||
2016 | * @see UTF8::is_ascii() |
||
2017 | * |
||
2018 | * @param string $str |
||
2019 | * |
||
2020 | * @return boolean |
||
2021 | * |
||
2022 | * @deprecated <p>use "UTF8::is_ascii()"</p> |
||
2023 | */ |
||
2024 | 1 | public static function isAscii(string $str): bool |
|
2028 | |||
2029 | /** |
||
2030 | * alias for "UTF8::is_base64()" |
||
2031 | * |
||
2032 | * @see UTF8::is_base64() |
||
2033 | * |
||
2034 | * @param string $str |
||
2035 | * |
||
2036 | * @return bool |
||
2037 | * |
||
2038 | * @deprecated <p>use "UTF8::is_base64()"</p> |
||
2039 | */ |
||
2040 | 1 | public static function isBase64(string $str): bool |
|
2044 | |||
2045 | /** |
||
2046 | * alias for "UTF8::is_binary()" |
||
2047 | * |
||
2048 | * @see UTF8::is_binary() |
||
2049 | * |
||
2050 | * @param mixed $str |
||
2051 | * @param bool $strict |
||
2052 | * |
||
2053 | * @return bool |
||
2054 | * |
||
2055 | * @deprecated <p>use "UTF8::is_binary()"</p> |
||
2056 | */ |
||
2057 | 2 | public static function isBinary($str, $strict = false): bool |
|
2061 | |||
2062 | /** |
||
2063 | * alias for "UTF8::is_bom()" |
||
2064 | * |
||
2065 | * @see UTF8::is_bom() |
||
2066 | * |
||
2067 | * @param string $utf8_chr |
||
2068 | * |
||
2069 | * @return boolean |
||
2070 | * |
||
2071 | * @deprecated <p>use "UTF8::is_bom()"</p> |
||
2072 | */ |
||
2073 | 1 | public static function isBom(string $utf8_chr): bool |
|
2077 | |||
2078 | /** |
||
2079 | * alias for "UTF8::is_html()" |
||
2080 | * |
||
2081 | * @see UTF8::is_html() |
||
2082 | * |
||
2083 | * @param string $str |
||
2084 | * |
||
2085 | * @return boolean |
||
2086 | * |
||
2087 | * @deprecated <p>use "UTF8::is_html()"</p> |
||
2088 | */ |
||
2089 | 1 | public static function isHtml(string $str): bool |
|
2093 | |||
2094 | /** |
||
2095 | * alias for "UTF8::is_json()" |
||
2096 | * |
||
2097 | * @see UTF8::is_json() |
||
2098 | * |
||
2099 | * @param string $str |
||
2100 | * |
||
2101 | * @return bool |
||
2102 | * |
||
2103 | * @deprecated <p>use "UTF8::is_json()"</p> |
||
2104 | */ |
||
2105 | public static function isJson(string $str): bool |
||
2109 | |||
2110 | /** |
||
2111 | * alias for "UTF8::is_utf16()" |
||
2112 | * |
||
2113 | * @see UTF8::is_utf16() |
||
2114 | * |
||
2115 | * @param string $str |
||
2116 | * |
||
2117 | * @return int|false false if is't not UTF16, 1 for UTF-16LE, 2 for UTF-16BE. |
||
2118 | * |
||
2119 | * @deprecated <p>use "UTF8::is_utf16()"</p> |
||
2120 | */ |
||
2121 | 1 | public static function isUtf16(string $str) |
|
2125 | |||
2126 | /** |
||
2127 | * alias for "UTF8::is_utf32()" |
||
2128 | * |
||
2129 | * @see UTF8::is_utf32() |
||
2130 | * |
||
2131 | * @param string $str |
||
2132 | * |
||
2133 | * @return int|false false if is't not UTF16, 1 for UTF-32LE, 2 for UTF-32BE. |
||
2134 | * |
||
2135 | * @deprecated <p>use "UTF8::is_utf32()"</p> |
||
2136 | */ |
||
2137 | 1 | public static function isUtf32(string $str) |
|
2141 | |||
2142 | /** |
||
2143 | * alias for "UTF8::is_utf8()" |
||
2144 | * |
||
2145 | * @see UTF8::is_utf8() |
||
2146 | * |
||
2147 | * @param string $str |
||
2148 | * @param bool $strict |
||
2149 | * |
||
2150 | * @return bool |
||
2151 | * |
||
2152 | * @deprecated <p>use "UTF8::is_utf8()"</p> |
||
2153 | */ |
||
2154 | 16 | public static function isUtf8($str, $strict = false): bool |
|
2158 | |||
2159 | /** |
||
2160 | * Checks if a string is 7 bit ASCII. |
||
2161 | * |
||
2162 | * @param string $str <p>The string to check.</p> |
||
2163 | * |
||
2164 | * @return bool <p> |
||
2165 | * <strong>true</strong> if it is ASCII<br> |
||
2166 | * <strong>false</strong> otherwise |
||
2167 | * </p> |
||
2168 | */ |
||
2169 | 58 | public static function is_ascii(string $str): bool |
|
2177 | |||
2178 | /** |
||
2179 | * Returns true if the string is base64 encoded, false otherwise. |
||
2180 | * |
||
2181 | * @param string $str <p>The input string.</p> |
||
2182 | * |
||
2183 | * @return bool <p>Whether or not $str is base64 encoded.</p> |
||
2184 | */ |
||
2185 | 1 | public static function is_base64(string $str): bool |
|
2191 | |||
2192 | /** |
||
2193 | * Check if the input is binary... (is look like a hack). |
||
2194 | * |
||
2195 | * @param mixed $input |
||
2196 | * @param bool $strict |
||
2197 | * |
||
2198 | * @return bool |
||
2199 | */ |
||
2200 | 19 | public static function is_binary($input, bool $strict = false): bool |
|
2243 | |||
2244 | /** |
||
2245 | * Check if the file is binary. |
||
2246 | * |
||
2247 | * @param string $file |
||
2248 | * |
||
2249 | * @return boolean |
||
2250 | */ |
||
2251 | 3 | public static function is_binary_file($file): bool |
|
2263 | |||
2264 | /** |
||
2265 | * Checks if the given string is equal to any "Byte Order Mark". |
||
2266 | * |
||
2267 | * WARNING: Use "UTF8::string_has_bom()" if you will check BOM in a string. |
||
2268 | * |
||
2269 | * @param string $str <p>The input string.</p> |
||
2270 | * |
||
2271 | * @return bool <p><strong>true</strong> if the $utf8_chr is Byte Order Mark, <strong>false</strong> otherwise.</p> |
||
2272 | */ |
||
2273 | 1 | public static function is_bom($str): bool |
|
2283 | |||
2284 | /** |
||
2285 | * Check if the string contains any html-tags <lall>. |
||
2286 | * |
||
2287 | * @param string $str <p>The input string.</p> |
||
2288 | * |
||
2289 | * @return boolean |
||
2290 | */ |
||
2291 | 1 | public static function is_html(string $str): bool |
|
2304 | |||
2305 | /** |
||
2306 | * Try to check if "$str" is an json-string. |
||
2307 | * |
||
2308 | * @param string $str <p>The input string.</p> |
||
2309 | * |
||
2310 | * @return bool |
||
2311 | */ |
||
2312 | 1 | public static function is_json(string $str): bool |
|
2328 | |||
2329 | /** |
||
2330 | * Check if the string is UTF-16. |
||
2331 | * |
||
2332 | * @param string $str <p>The input string.</p> |
||
2333 | * |
||
2334 | * @return int|false <p> |
||
2335 | * <strong>false</strong> if is't not UTF-16,<br> |
||
2336 | * <strong>1</strong> for UTF-16LE,<br> |
||
2337 | * <strong>2</strong> for UTF-16BE. |
||
2338 | * </p> |
||
2339 | */ |
||
2340 | 10 | View Code Duplication | public static function is_utf16(string $str) |
2395 | |||
2396 | /** |
||
2397 | * Check if the string is UTF-32. |
||
2398 | * |
||
2399 | * @param string $str |
||
2400 | * |
||
2401 | * @return int|false <p> |
||
2402 | * <strong>false</strong> if is't not UTF-32,<br> |
||
2403 | * <strong>1</strong> for UTF-32LE,<br> |
||
2404 | * <strong>2</strong> for UTF-32BE. |
||
2405 | * </p> |
||
2406 | */ |
||
2407 | 8 | View Code Duplication | public static function is_utf32(string $str) |
2462 | |||
2463 | /** |
||
2464 | * Checks whether the passed string contains only byte sequences that appear valid UTF-8 characters. |
||
2465 | * |
||
2466 | * @see http://hsivonen.iki.fi/php-utf8/ |
||
2467 | * |
||
2468 | * @param string|string[] $str <p>The string to be checked.</p> |
||
2469 | * @param bool $strict <p>Check also if the string is not UTF-16 or UTF-32.</p> |
||
2470 | * |
||
2471 | * @return bool |
||
2472 | */ |
||
2473 | 61 | public static function is_utf8($str, bool $strict = false): bool |
|
2621 | |||
2622 | /** |
||
2623 | * (PHP 5 >= 5.2.0, PECL json >= 1.2.0)<br/> |
||
2624 | * Decodes a JSON string |
||
2625 | * |
||
2626 | * @link http://php.net/manual/en/function.json-decode.php |
||
2627 | * |
||
2628 | * @param string $json <p> |
||
2629 | * The <i>json</i> string being decoded. |
||
2630 | * </p> |
||
2631 | * <p> |
||
2632 | * This function only works with UTF-8 encoded strings. |
||
2633 | * </p> |
||
2634 | * <p>PHP implements a superset of |
||
2635 | * JSON - it will also encode and decode scalar types and <b>NULL</b>. The JSON standard |
||
2636 | * only supports these values when they are nested inside an array or an object. |
||
2637 | * </p> |
||
2638 | * @param bool $assoc [optional] <p> |
||
2639 | * When <b>TRUE</b>, returned objects will be converted into |
||
2640 | * associative arrays. |
||
2641 | * </p> |
||
2642 | * @param int $depth [optional] <p> |
||
2643 | * User specified recursion depth. |
||
2644 | * </p> |
||
2645 | * @param int $options [optional] <p> |
||
2646 | * Bitmask of JSON decode options. Currently only |
||
2647 | * <b>JSON_BIGINT_AS_STRING</b> |
||
2648 | * is supported (default is to cast large integers as floats) |
||
2649 | * </p> |
||
2650 | * |
||
2651 | * @return mixed the value encoded in <i>json</i> in appropriate |
||
2652 | * PHP type. Values true, false and |
||
2653 | * null (case-insensitive) are returned as <b>TRUE</b>, <b>FALSE</b> |
||
2654 | * and <b>NULL</b> respectively. <b>NULL</b> is returned if the |
||
2655 | * <i>json</i> cannot be decoded or if the encoded |
||
2656 | * data is deeper than the recursion limit. |
||
2657 | */ |
||
2658 | 2 | public static function json_decode(string $json, bool $assoc = false, int $depth = 512, int $options = 0) |
|
2666 | |||
2667 | /** |
||
2668 | * (PHP 5 >= 5.2.0, PECL json >= 1.2.0)<br/> |
||
2669 | * Returns the JSON representation of a value. |
||
2670 | * |
||
2671 | * @link http://php.net/manual/en/function.json-encode.php |
||
2672 | * |
||
2673 | * @param mixed $value <p> |
||
2674 | * The <i>value</i> being encoded. Can be any type except |
||
2675 | * a resource. |
||
2676 | * </p> |
||
2677 | * <p> |
||
2678 | * All string data must be UTF-8 encoded. |
||
2679 | * </p> |
||
2680 | * <p>PHP implements a superset of |
||
2681 | * JSON - it will also encode and decode scalar types and <b>NULL</b>. The JSON standard |
||
2682 | * only supports these values when they are nested inside an array or an object. |
||
2683 | * </p> |
||
2684 | * @param int $options [optional] <p> |
||
2685 | * Bitmask consisting of <b>JSON_HEX_QUOT</b>, |
||
2686 | * <b>JSON_HEX_TAG</b>, |
||
2687 | * <b>JSON_HEX_AMP</b>, |
||
2688 | * <b>JSON_HEX_APOS</b>, |
||
2689 | * <b>JSON_NUMERIC_CHECK</b>, |
||
2690 | * <b>JSON_PRETTY_PRINT</b>, |
||
2691 | * <b>JSON_UNESCAPED_SLASHES</b>, |
||
2692 | * <b>JSON_FORCE_OBJECT</b>, |
||
2693 | * <b>JSON_UNESCAPED_UNICODE</b>. The behaviour of these |
||
2694 | * constants is described on |
||
2695 | * the JSON constants page. |
||
2696 | * </p> |
||
2697 | * @param int $depth [optional] <p> |
||
2698 | * Set the maximum depth. Must be greater than zero. |
||
2699 | * </p> |
||
2700 | * |
||
2701 | * @return string a JSON encoded string on success or <b>FALSE</b> on failure. |
||
2702 | */ |
||
2703 | 2 | public static function json_encode($value, int $options = 0, int $depth = 512): string |
|
2711 | |||
2712 | /** |
||
2713 | * Makes string's first char lowercase. |
||
2714 | * |
||
2715 | * @param string $str <p>The input string</p> |
||
2716 | * @param string $encoding [optional] <p>Set the charset.</p> |
||
2717 | * @param bool $cleanUtf8 [optional] <p>Remove non UTF-8 chars from the string.</p> |
||
2718 | * |
||
2719 | * @return string <p>The resulting string</p> |
||
2720 | */ |
||
2721 | 7 | public static function lcfirst(string $str, string $encoding = 'UTF-8', bool $cleanUtf8 = false): string |
|
2736 | |||
2737 | /** |
||
2738 | * alias for "UTF8::lcfirst()" |
||
2739 | * |
||
2740 | * @see UTF8::lcfirst() |
||
2741 | * |
||
2742 | * @param string $word |
||
2743 | * @param string $encoding |
||
2744 | * @param bool $cleanUtf8 |
||
2745 | * |
||
2746 | * @return string |
||
2747 | */ |
||
2748 | 1 | public static function lcword(string $word, string $encoding = 'UTF-8', bool $cleanUtf8 = false): string |
|
2752 | |||
2753 | /** |
||
2754 | * Lowercase for all words in the string. |
||
2755 | * |
||
2756 | * @param string $str <p>The input string.</p> |
||
2757 | * @param string[] $exceptions [optional] <p>Exclusion for some words.</p> |
||
2758 | * @param string $charlist [optional] <p>Additional chars that contains to words and do not start a new word.</p> |
||
2759 | * @param string $encoding [optional] <p>Set the charset.</p> |
||
2760 | * @param bool $cleanUtf8 [optional] <p>Remove non UTF-8 chars from the string.</p> |
||
2761 | * |
||
2762 | * @return string |
||
2763 | */ |
||
2764 | 1 | public static function lcwords(string $str, array $exceptions = [], string $charlist = '', string $encoding = 'UTF-8', bool $cleanUtf8 = false): string |
|
2802 | |||
2803 | /** |
||
2804 | * Strip whitespace or other characters from beginning of a UTF-8 string. |
||
2805 | * |
||
2806 | * @param string $str <p>The string to be trimmed</p> |
||
2807 | * @param mixed $chars <p>Optional characters to be stripped</p> |
||
2808 | * |
||
2809 | * @return string <p>The string with unwanted characters stripped from the left.</p> |
||
2810 | */ |
||
2811 | 24 | View Code Duplication | public static function ltrim(string $str = '', $chars = INF): string |
2824 | |||
2825 | /** |
||
2826 | * Returns the UTF-8 character with the maximum code point in the given data. |
||
2827 | * |
||
2828 | * @param mixed $arg <p>A UTF-8 encoded string or an array of such strings.</p> |
||
2829 | * |
||
2830 | * @return string <p>The character with the highest code point than others.</p> |
||
2831 | */ |
||
2832 | 1 | View Code Duplication | public static function max($arg): string |
2840 | |||
2841 | /** |
||
2842 | * Calculates and returns the maximum number of bytes taken by any |
||
2843 | * UTF-8 encoded character in the given string. |
||
2844 | * |
||
2845 | * @param string $str <p>The original Unicode string.</p> |
||
2846 | * |
||
2847 | * @return int <p>Max byte lengths of the given chars.</p> |
||
2848 | */ |
||
2849 | 1 | public static function max_chr_width(string $str): int |
|
2858 | |||
2859 | /** |
||
2860 | * Checks whether mbstring is available on the server. |
||
2861 | * |
||
2862 | * @return bool <p><strong>true</strong> if available, <strong>false</strong> otherwise.</p> |
||
2863 | */ |
||
2864 | 12 | public static function mbstring_loaded(): bool |
|
2874 | |||
2875 | 1 | private static function mbstring_overloaded(): bool |
|
2881 | |||
2882 | /** |
||
2883 | * Returns the UTF-8 character with the minimum code point in the given data. |
||
2884 | * |
||
2885 | * @param mixed $arg <strong>A UTF-8 encoded string or an array of such strings.</strong> |
||
2886 | * |
||
2887 | * @return string <p>The character with the lowest code point than others.</p> |
||
2888 | */ |
||
2889 | 1 | View Code Duplication | public static function min($arg): string |
2897 | |||
2898 | /** |
||
2899 | * alias for "UTF8::normalize_encoding()" |
||
2900 | * |
||
2901 | * @see UTF8::normalize_encoding() |
||
2902 | * |
||
2903 | * @param string $encoding |
||
2904 | * @param mixed $fallback |
||
2905 | * |
||
2906 | * @return string |
||
2907 | * |
||
2908 | * @deprecated <p>use "UTF8::normalize_encoding()"</p> |
||
2909 | */ |
||
2910 | 1 | public static function normalizeEncoding(string $encoding, $fallback = '') |
|
2914 | |||
2915 | /** |
||
2916 | * Normalize the encoding-"name" input. |
||
2917 | * |
||
2918 | * @param string $encoding <p>e.g.: ISO, UTF8, WINDOWS-1251 etc.</p> |
||
2919 | * @param mixed $fallback <p>e.g.: UTF-8</p> |
||
2920 | * |
||
2921 | * @return string <p>e.g.: ISO-8859-1, UTF-8, WINDOWS-1251 etc.<br>Will return a empty string as fallback (by |
||
2922 | * default)</p> |
||
2923 | */ |
||
2924 | 27 | public static function normalize_encoding(string $encoding, $fallback = '') |
|
3032 | |||
3033 | /** |
||
3034 | * Normalize some MS Word special characters. |
||
3035 | * |
||
3036 | * @param string $str <p>The string to be normalized.</p> |
||
3037 | * |
||
3038 | * @return string |
||
3039 | */ |
||
3040 | 16 | View Code Duplication | public static function normalize_msword(string $str): string |
3061 | |||
3062 | /** |
||
3063 | * Normalize the whitespace. |
||
3064 | * |
||
3065 | * @param string $str <p>The string to be normalized.</p> |
||
3066 | * @param bool $keepNonBreakingSpace [optional] <p>Set to true, to keep non-breaking-spaces.</p> |
||
3067 | * @param bool $keepBidiUnicodeControls [optional] <p>Set to true, to keep non-printable (for the web) |
||
3068 | * bidirectional text chars.</p> |
||
3069 | * |
||
3070 | * @return string |
||
3071 | */ |
||
3072 | 39 | public static function normalize_whitespace(string $str, bool $keepNonBreakingSpace = false, bool $keepBidiUnicodeControls = false): string |
|
3104 | |||
3105 | /** |
||
3106 | * Calculates Unicode code point of the given UTF-8 encoded character. |
||
3107 | * |
||
3108 | * INFO: opposite to UTF8::chr() |
||
3109 | * |
||
3110 | * @param string $chr <p>The character of which to calculate code point.<p/> |
||
3111 | * @param string $encoding [optional] <p>Default is UTF-8</p> |
||
3112 | * |
||
3113 | * @return int <p> |
||
3114 | * Unicode code point of the given character,<br> |
||
3115 | * 0 on invalid UTF-8 byte sequence. |
||
3116 | * </p> |
||
3117 | */ |
||
3118 | 23 | public static function ord(string $chr, string $encoding = 'UTF-8'): int |
|
3170 | |||
3171 | /** |
||
3172 | * Parses the string into an array (into the the second parameter). |
||
3173 | * |
||
3174 | * WARNING: Instead of "parse_str()" this method do not (re-)placing variables in the current scope, |
||
3175 | * if the second parameter is not set! |
||
3176 | * |
||
3177 | * @link http://php.net/manual/en/function.parse-str.php |
||
3178 | * |
||
3179 | * @param string $str <p>The input string.</p> |
||
3180 | * @param array $result <p>The result will be returned into this reference parameter.</p> |
||
3181 | * @param bool $cleanUtf8 [optional] <p>Remove non UTF-8 chars from the string.</p> |
||
3182 | * |
||
3183 | * @return bool <p>Will return <strong>false</strong> if php can't parse the string and we haven't any $result.</p> |
||
3184 | */ |
||
3185 | 1 | public static function parse_str(string $str, &$result, bool $cleanUtf8 = false): bool |
|
3196 | |||
3197 | /** |
||
3198 | * Checks if \u modifier is available that enables Unicode support in PCRE. |
||
3199 | * |
||
3200 | * @return bool <p><strong>true</strong> if support is available, <strong>false</strong> otherwise.</p> |
||
3201 | */ |
||
3202 | 60 | public static function pcre_utf8_support(): bool |
|
3207 | |||
3208 | /** |
||
3209 | * Create an array containing a range of UTF-8 characters. |
||
3210 | * |
||
3211 | * @param mixed $var1 <p>Numeric or hexadecimal code points, or a UTF-8 character to start from.</p> |
||
3212 | * @param mixed $var2 <p>Numeric or hexadecimal code points, or a UTF-8 character to end at.</p> |
||
3213 | * |
||
3214 | * @return array |
||
3215 | */ |
||
3216 | 1 | public static function range($var1, $var2): array |
|
3254 | |||
3255 | /** |
||
3256 | * Multi decode html entity & fix urlencoded-win1252-chars. |
||
3257 | * |
||
3258 | * e.g: |
||
3259 | * 'test+test' => 'test+test' |
||
3260 | * 'Düsseldorf' => 'Düsseldorf' |
||
3261 | * 'D%FCsseldorf' => 'Düsseldorf' |
||
3262 | * 'Düsseldorf' => 'Düsseldorf' |
||
3263 | * 'D%26%23xFC%3Bsseldorf' => 'Düsseldorf' |
||
3264 | * 'Düsseldorf' => 'Düsseldorf' |
||
3265 | * 'D%C3%BCsseldorf' => 'Düsseldorf' |
||
3266 | * 'D%C3%83%C2%BCsseldorf' => 'Düsseldorf' |
||
3267 | * 'D%25C3%2583%25C2%25BCsseldorf' => 'Düsseldorf' |
||
3268 | * |
||
3269 | * @param string $str <p>The input string.</p> |
||
3270 | * @param bool $multi_decode <p>Decode as often as possible.</p> |
||
3271 | * |
||
3272 | * @return string |
||
3273 | */ |
||
3274 | 2 | View Code Duplication | public static function rawurldecode(string $str, bool $multi_decode = true): string |
3303 | |||
3304 | /** |
||
3305 | * alias for "UTF8::remove_bom()" |
||
3306 | * |
||
3307 | * @see UTF8::remove_bom() |
||
3308 | * |
||
3309 | * @param string $str |
||
3310 | * |
||
3311 | * @return string |
||
3312 | * |
||
3313 | * @deprecated <p>use "UTF8::remove_bom()"</p> |
||
3314 | */ |
||
3315 | public static function removeBOM(string $str): string |
||
3319 | |||
3320 | /** |
||
3321 | * Remove the BOM from UTF-8 / UTF-16 / UTF-32 strings. |
||
3322 | * |
||
3323 | * @param string $str <p>The input string.</p> |
||
3324 | * |
||
3325 | * @return string <p>String without UTF-BOM</p> |
||
3326 | */ |
||
3327 | 43 | public static function remove_bom(string $str): string |
|
3345 | |||
3346 | /** |
||
3347 | * Removes duplicate occurrences of a string in another string. |
||
3348 | * |
||
3349 | * @param string $str <p>The base string.</p> |
||
3350 | * @param string|string[] $what <p>String to search for in the base string.</p> |
||
3351 | * |
||
3352 | * @return string <p>The result string with removed duplicates.</p> |
||
3353 | */ |
||
3354 | 1 | public static function remove_duplicates(string $str, $what = ' '): string |
|
3369 | |||
3370 | /** |
||
3371 | * Remove invisible characters from a string. |
||
3372 | * |
||
3373 | * e.g.: This prevents sandwiching null characters between ascii characters, like Java\0script. |
||
3374 | * |
||
3375 | * copy&past from https://github.com/bcit-ci/CodeIgniter/blob/develop/system/core/Common.php |
||
3376 | * |
||
3377 | * @param string $str |
||
3378 | * @param bool $url_encoded |
||
3379 | * @param string $replacement |
||
3380 | * |
||
3381 | * @return string |
||
3382 | */ |
||
3383 | 65 | public static function remove_invisible_characters(string $str, bool $url_encoded = true, string $replacement = ''): string |
|
3403 | |||
3404 | /** |
||
3405 | * Replace the diamond question mark (�) and invalid-UTF8 chars with the replacement. |
||
3406 | * |
||
3407 | * @param string $str <p>The input string</p> |
||
3408 | * @param string $replacementChar <p>The replacement character.</p> |
||
3409 | * @param bool $processInvalidUtf8 <p>Convert invalid UTF-8 chars </p> |
||
3410 | * |
||
3411 | * @return string |
||
3412 | */ |
||
3413 | 37 | public static function replace_diamond_question_mark(string $str, string $replacementChar = '', bool $processInvalidUtf8 = true): string |
|
3453 | |||
3454 | /** |
||
3455 | * Strip whitespace or other characters from end of a UTF-8 string. |
||
3456 | * |
||
3457 | * @param string $str <p>The string to be trimmed.</p> |
||
3458 | * @param mixed $chars <p>Optional characters to be stripped.</p> |
||
3459 | * |
||
3460 | * @return string <p>The string with unwanted characters stripped from the right.</p> |
||
3461 | */ |
||
3462 | 23 | View Code Duplication | public static function rtrim(string $str = '', $chars = INF): string |
3475 | |||
3476 | /** |
||
3477 | * rxClass |
||
3478 | * |
||
3479 | * @param string $s |
||
3480 | * @param string $class |
||
3481 | * |
||
3482 | * @return string |
||
3483 | */ |
||
3484 | 60 | private static function rxClass(string $s, string $class = ''): string |
|
3524 | |||
3525 | /** |
||
3526 | * WARNING: Print native UTF-8 support (libs), e.g. for debugging. |
||
3527 | */ |
||
3528 | 1 | public static function showSupport() |
|
3540 | |||
3541 | /** |
||
3542 | * Converts a UTF-8 character to HTML Numbered Entity like "{". |
||
3543 | * |
||
3544 | * @param string $char <p>The Unicode character to be encoded as numbered entity.</p> |
||
3545 | * @param bool $keepAsciiChars <p>Set to <strong>true</strong> to keep ASCII chars.</> |
||
3546 | * @param string $encoding [optional] <p>Default is UTF-8</p> |
||
3547 | * |
||
3548 | * @return string <p>The HTML numbered entity.</p> |
||
3549 | */ |
||
3550 | 1 | public static function single_chr_html_encode(string $char, bool $keepAsciiChars = false, string $encoding = 'UTF-8'): string |
|
3570 | |||
3571 | /** |
||
3572 | * Convert a string to an array of Unicode characters. |
||
3573 | * |
||
3574 | * @param string $str <p>The string to split into array.</p> |
||
3575 | * @param int $length [optional] <p>Max character length of each array element.</p> |
||
3576 | * @param bool $cleanUtf8 [optional] <p>Remove non UTF-8 chars from the string.</p> |
||
3577 | * |
||
3578 | * @return string[] <p>An array containing chunks of the string.</p> |
||
3579 | */ |
||
3580 | 39 | public static function split(string $str, int $length = 1, bool $cleanUtf8 = false): array |
|
3688 | |||
3689 | /** |
||
3690 | * Optimized "\mb_detect_encoding()"-function -> with support for UTF-16 and UTF-32. |
||
3691 | * |
||
3692 | * @param string $str <p>The input string.</p> |
||
3693 | * |
||
3694 | * @return false|string <p> |
||
3695 | * The detected string-encoding e.g. UTF-8 or UTF-16BE,<br> |
||
3696 | * otherwise it will return false e.g. for BINARY or not detected encoding. |
||
3697 | * </p> |
||
3698 | */ |
||
3699 | 15 | public static function str_detect_encoding(string $str) |
|
3807 | |||
3808 | /** |
||
3809 | * Check if the string ends with the given substring. |
||
3810 | * |
||
3811 | * @param string $haystack <p>The string to search in.</p> |
||
3812 | * @param string $needle <p>The substring to search for.</p> |
||
3813 | * |
||
3814 | * @return bool |
||
3815 | */ |
||
3816 | 2 | View Code Duplication | public static function str_ends_with(string $haystack, string $needle): bool |
3828 | |||
3829 | /** |
||
3830 | * Check if the string ends with the given substring, case insensitive. |
||
3831 | * |
||
3832 | * @param string $haystack <p>The string to search in.</p> |
||
3833 | * @param string $needle <p>The substring to search for.</p> |
||
3834 | * |
||
3835 | * @return bool |
||
3836 | */ |
||
3837 | 2 | View Code Duplication | public static function str_iends_with(string $haystack, string $needle): bool |
3849 | |||
3850 | /** |
||
3851 | * Case-insensitive and UTF-8 safe version of <function>str_replace</function>. |
||
3852 | * |
||
3853 | * @link http://php.net/manual/en/function.str-ireplace.php |
||
3854 | * |
||
3855 | * @param mixed $search <p> |
||
3856 | * Every replacement with search array is |
||
3857 | * performed on the result of previous replacement. |
||
3858 | * </p> |
||
3859 | * @param mixed $replace <p> |
||
3860 | * </p> |
||
3861 | * @param mixed $subject <p> |
||
3862 | * If subject is an array, then the search and |
||
3863 | * replace is performed with every entry of |
||
3864 | * subject, and the return value is an array as |
||
3865 | * well. |
||
3866 | * </p> |
||
3867 | * @param int $count [optional] <p> |
||
3868 | * The number of matched and replaced needles will |
||
3869 | * be returned in count which is passed by |
||
3870 | * reference. |
||
3871 | * </p> |
||
3872 | * |
||
3873 | * @return mixed <p>A string or an array of replacements.</p> |
||
3874 | */ |
||
3875 | 26 | public static function str_ireplace($search, $replace, $subject, &$count = null) |
|
3893 | |||
3894 | /** |
||
3895 | * Check if the string starts with the given substring, case insensitive. |
||
3896 | * |
||
3897 | * @param string $haystack <p>The string to search in.</p> |
||
3898 | * @param string $needle <p>The substring to search for.</p> |
||
3899 | * |
||
3900 | * @return bool |
||
3901 | */ |
||
3902 | 2 | View Code Duplication | public static function str_istarts_with(string $haystack, string $needle): bool |
3914 | |||
3915 | /** |
||
3916 | * Limit the number of characters in a string, but also after the next word. |
||
3917 | * |
||
3918 | * @param string $str |
||
3919 | * @param int $length |
||
3920 | * @param string $strAddOn |
||
3921 | * |
||
3922 | * @return string |
||
3923 | */ |
||
3924 | 1 | public static function str_limit_after_word(string $str, int $length = 100, string $strAddOn = '…'): string |
|
3951 | |||
3952 | /** |
||
3953 | * Pad a UTF-8 string to given length with another string. |
||
3954 | * |
||
3955 | * @param string $str <p>The input string.</p> |
||
3956 | * @param int $pad_length <p>The length of return string.</p> |
||
3957 | * @param string $pad_string [optional] <p>String to use for padding the input string.</p> |
||
3958 | * @param int $pad_type [optional] <p> |
||
3959 | * Can be <strong>STR_PAD_RIGHT</strong> (default), |
||
3960 | * <strong>STR_PAD_LEFT</strong> or <strong>STR_PAD_BOTH</strong> |
||
3961 | * </p> |
||
3962 | * |
||
3963 | * @return string <strong>Returns the padded string</strong> |
||
3964 | */ |
||
3965 | 2 | public static function str_pad(string $str, int $pad_length, string $pad_string = ' ', int $pad_type = STR_PAD_RIGHT): string |
|
4006 | |||
4007 | /** |
||
4008 | * Repeat a string. |
||
4009 | * |
||
4010 | * @param string $str <p> |
||
4011 | * The string to be repeated. |
||
4012 | * </p> |
||
4013 | * @param int $multiplier <p> |
||
4014 | * Number of time the input string should be |
||
4015 | * repeated. |
||
4016 | * </p> |
||
4017 | * <p> |
||
4018 | * multiplier has to be greater than or equal to 0. |
||
4019 | * If the multiplier is set to 0, the function |
||
4020 | * will return an empty string. |
||
4021 | * </p> |
||
4022 | * |
||
4023 | * @return string <p>The repeated string.</p> |
||
4024 | */ |
||
4025 | 1 | public static function str_repeat(string $str, int $multiplier): string |
|
4031 | |||
4032 | /** |
||
4033 | * INFO: This is only a wrapper for "str_replace()" -> the original functions is already UTF-8 safe. |
||
4034 | * |
||
4035 | * Replace all occurrences of the search string with the replacement string |
||
4036 | * |
||
4037 | * @link http://php.net/manual/en/function.str-replace.php |
||
4038 | * |
||
4039 | * @param mixed $search <p> |
||
4040 | * The value being searched for, otherwise known as the needle. |
||
4041 | * An array may be used to designate multiple needles. |
||
4042 | * </p> |
||
4043 | * @param mixed $replace <p> |
||
4044 | * The replacement value that replaces found search |
||
4045 | * values. An array may be used to designate multiple replacements. |
||
4046 | * </p> |
||
4047 | * @param mixed $subject <p> |
||
4048 | * The string or array being searched and replaced on, |
||
4049 | * otherwise known as the haystack. |
||
4050 | * </p> |
||
4051 | * <p> |
||
4052 | * If subject is an array, then the search and |
||
4053 | * replace is performed with every entry of |
||
4054 | * subject, and the return value is an array as |
||
4055 | * well. |
||
4056 | * </p> |
||
4057 | * @param int $count [optional] If passed, this will hold the number of matched and replaced needles. |
||
4058 | * |
||
4059 | * @return mixed <p>This function returns a string or an array with the replaced values.</p> |
||
4060 | */ |
||
4061 | 12 | public static function str_replace($search, $replace, $subject, int &$count = null) |
|
4065 | |||
4066 | /** |
||
4067 | * Replace the first "$search"-term with the "$replace"-term. |
||
4068 | * |
||
4069 | * @param string $search |
||
4070 | * @param string $replace |
||
4071 | * @param string $subject |
||
4072 | * |
||
4073 | * @return string |
||
4074 | */ |
||
4075 | 1 | public static function str_replace_first(string $search, string $replace, string $subject): string |
|
4085 | |||
4086 | /** |
||
4087 | * Shuffles all the characters in the string. |
||
4088 | * |
||
4089 | * @param string $str <p>The input string</p> |
||
4090 | * |
||
4091 | * @return string <p>The shuffled string.</p> |
||
4092 | */ |
||
4093 | 1 | public static function str_shuffle(string $str): string |
|
4101 | |||
4102 | /** |
||
4103 | * Sort all characters according to code points. |
||
4104 | * |
||
4105 | * @param string $str <p>A UTF-8 string.</p> |
||
4106 | * @param bool $unique <p>Sort unique. If <strong>true</strong>, repeated characters are ignored.</p> |
||
4107 | * @param bool $desc <p>If <strong>true</strong>, will sort characters in reverse code point order.</p> |
||
4108 | * |
||
4109 | * @return string <p>String of sorted characters.</p> |
||
4110 | */ |
||
4111 | 1 | public static function str_sort(string $str, bool $unique = false, bool $desc = false): string |
|
4127 | |||
4128 | /** |
||
4129 | * Split a string into an array. |
||
4130 | * |
||
4131 | * @param string|string[] $str |
||
4132 | * @param int $len |
||
4133 | * |
||
4134 | * @return array |
||
4135 | */ |
||
4136 | 23 | public static function str_split($str, int $len = 1): array |
|
4176 | |||
4177 | /** |
||
4178 | * Check if the string starts with the given substring. |
||
4179 | * |
||
4180 | * @param string $haystack <p>The string to search in.</p> |
||
4181 | * @param string $needle <p>The substring to search for.</p> |
||
4182 | * |
||
4183 | * @return bool |
||
4184 | */ |
||
4185 | 2 | View Code Duplication | public static function str_starts_with(string $haystack, string $needle): bool |
4197 | |||
4198 | /** |
||
4199 | * Get a binary representation of a specific string. |
||
4200 | * |
||
4201 | * @param string $str <p>The input string.</p> |
||
4202 | * |
||
4203 | * @return string |
||
4204 | */ |
||
4205 | 1 | public static function str_to_binary(string $str): string |
|
4211 | |||
4212 | /** |
||
4213 | * Convert a string into an array of words. |
||
4214 | * |
||
4215 | * @param string $str |
||
4216 | * @param string $charList <p>Additional chars for the definition of "words".</p> |
||
4217 | * @param bool $removeEmptyValues <p>Remove empty values.</p> |
||
4218 | * @param null|int $removeShortValues |
||
4219 | * |
||
4220 | * @return array |
||
4221 | */ |
||
4222 | 10 | public static function str_to_words(string $str, string $charList = '', bool $removeEmptyValues = false, int $removeShortValues = null): array |
|
4267 | |||
4268 | /** |
||
4269 | * alias for "UTF8::to_ascii()" |
||
4270 | * |
||
4271 | * @see UTF8::to_ascii() |
||
4272 | * |
||
4273 | * @param string $str |
||
4274 | * @param string $unknown |
||
4275 | * @param bool $strict |
||
4276 | * |
||
4277 | * @return string |
||
4278 | */ |
||
4279 | 7 | public static function str_transliterate(string $str, string $unknown = '?', bool $strict = false): string |
|
4283 | |||
4284 | /** |
||
4285 | * Counts number of words in the UTF-8 string. |
||
4286 | * |
||
4287 | * @param string $str <p>The input string.</p> |
||
4288 | * @param int $format [optional] <p> |
||
4289 | * <strong>0</strong> => return a number of words (default)<br> |
||
4290 | * <strong>1</strong> => return an array of words<br> |
||
4291 | * <strong>2</strong> => return an array of words with word-offset as key |
||
4292 | * </p> |
||
4293 | * @param string $charlist [optional] <p>Additional chars that contains to words and do not start a new word.</p> |
||
4294 | * |
||
4295 | * @return array|int <p>The number of words in the string</p> |
||
4296 | */ |
||
4297 | 1 | public static function str_word_count(string $str, int $format = 0, string $charlist = '') |
|
4327 | |||
4328 | /** |
||
4329 | * Case-insensitive string comparison. |
||
4330 | * |
||
4331 | * INFO: Case-insensitive version of UTF8::strcmp() |
||
4332 | * |
||
4333 | * @param string $str1 |
||
4334 | * @param string $str2 |
||
4335 | * |
||
4336 | * @return int <p> |
||
4337 | * <strong>< 0</strong> if str1 is less than str2;<br> |
||
4338 | * <strong>> 0</strong> if str1 is greater than str2,<br> |
||
4339 | * <strong>0</strong> if they are equal. |
||
4340 | * </p> |
||
4341 | */ |
||
4342 | 11 | public static function strcasecmp(string $str1, string $str2): int |
|
4346 | |||
4347 | /** |
||
4348 | * alias for "UTF8::strstr()" |
||
4349 | * |
||
4350 | * @see UTF8::strstr() |
||
4351 | * |
||
4352 | * @param string $haystack |
||
4353 | * @param string $needle |
||
4354 | * @param bool $before_needle |
||
4355 | * @param string $encoding |
||
4356 | * @param bool $cleanUtf8 |
||
4357 | * |
||
4358 | * @return string|false |
||
4359 | */ |
||
4360 | 1 | public static function strchr(string $haystack, string $needle, bool $before_needle = false, string $encoding = 'UTF-8', bool $cleanUtf8 = false) |
|
4364 | |||
4365 | /** |
||
4366 | * Case-sensitive string comparison. |
||
4367 | * |
||
4368 | * @param string $str1 |
||
4369 | * @param string $str2 |
||
4370 | * |
||
4371 | * @return int <p> |
||
4372 | * <strong>< 0</strong> if str1 is less than str2<br> |
||
4373 | * <strong>> 0</strong> if str1 is greater than str2<br> |
||
4374 | * <strong>0</strong> if they are equal. |
||
4375 | * </p> |
||
4376 | */ |
||
4377 | 14 | public static function strcmp(string $str1, string $str2): int |
|
4385 | |||
4386 | /** |
||
4387 | * Find length of initial segment not matching mask. |
||
4388 | * |
||
4389 | * @param string $str |
||
4390 | * @param string $charList |
||
4391 | * @param int $offset |
||
4392 | * @param int $length |
||
4393 | * |
||
4394 | * @return int|null |
||
4395 | */ |
||
4396 | 15 | public static function strcspn(string $str, string $charList, int $offset = 0, int $length = null) |
|
4420 | |||
4421 | /** |
||
4422 | * alias for "UTF8::stristr()" |
||
4423 | * |
||
4424 | * @see UTF8::stristr() |
||
4425 | * |
||
4426 | * @param string $haystack |
||
4427 | * @param string $needle |
||
4428 | * @param bool $before_needle |
||
4429 | * @param string $encoding |
||
4430 | * @param bool $cleanUtf8 |
||
4431 | * |
||
4432 | * @return string|false |
||
4433 | */ |
||
4434 | 1 | public static function strichr(string $haystack, string $needle, bool $before_needle = false, string $encoding = 'UTF-8', bool $cleanUtf8 = false) |
|
4438 | |||
4439 | /** |
||
4440 | * Create a UTF-8 string from code points. |
||
4441 | * |
||
4442 | * INFO: opposite to UTF8::codepoints() |
||
4443 | * |
||
4444 | * @param array $array <p>Integer or Hexadecimal codepoints.</p> |
||
4445 | * |
||
4446 | * @return string <p>UTF-8 encoded string.</p> |
||
4447 | */ |
||
4448 | 2 | public static function string(array $array): string |
|
4461 | |||
4462 | /** |
||
4463 | * Checks if string starts with "BOM" (Byte Order Mark Character) character. |
||
4464 | * |
||
4465 | * @param string $str <p>The input string.</p> |
||
4466 | * |
||
4467 | * @return bool <p><strong>true</strong> if the string has BOM at the start, <strong>false</strong> otherwise.</p> |
||
4468 | */ |
||
4469 | 3 | public static function string_has_bom(string $str): bool |
|
4479 | |||
4480 | /** |
||
4481 | * Strip HTML and PHP tags from a string + clean invalid UTF-8. |
||
4482 | * |
||
4483 | * @link http://php.net/manual/en/function.strip-tags.php |
||
4484 | * |
||
4485 | * @param string $str <p> |
||
4486 | * The input string. |
||
4487 | * </p> |
||
4488 | * @param string $allowable_tags [optional] <p> |
||
4489 | * You can use the optional second parameter to specify tags which should |
||
4490 | * not be stripped. |
||
4491 | * </p> |
||
4492 | * <p> |
||
4493 | * HTML comments and PHP tags are also stripped. This is hardcoded and |
||
4494 | * can not be changed with allowable_tags. |
||
4495 | * </p> |
||
4496 | * @param bool $cleanUtf8 [optional] <p>Remove non UTF-8 chars from the string.</p> |
||
4497 | * |
||
4498 | * @return string <p>The stripped string.</p> |
||
4499 | */ |
||
4500 | 2 | public static function strip_tags(string $str, string $allowable_tags = null, bool $cleanUtf8 = false): string |
|
4512 | |||
4513 | /** |
||
4514 | * Strip all whitespace characters. This includes tabs and newline |
||
4515 | * characters, as well as multibyte whitespace such as the thin space |
||
4516 | * and ideographic space. |
||
4517 | * |
||
4518 | * @param string $str |
||
4519 | * |
||
4520 | * @return string |
||
4521 | */ |
||
4522 | 12 | public static function strip_whitespace(string $str): string |
|
4530 | |||
4531 | /** |
||
4532 | * Finds position of first occurrence of a string within another, case insensitive. |
||
4533 | * |
||
4534 | * @link http://php.net/manual/en/function.mb-stripos.php |
||
4535 | * |
||
4536 | * @param string $haystack <p>The string from which to get the position of the first occurrence of needle.</p> |
||
4537 | * @param string $needle <p>The string to find in haystack.</p> |
||
4538 | * @param int $offset [optional] <p>The position in haystack to start searching.</p> |
||
4539 | * @param string $encoding [optional] <p>Set the charset.</p> |
||
4540 | * @param bool $cleanUtf8 [optional] <p>Remove non UTF-8 chars from the string.</p> |
||
4541 | * |
||
4542 | * @return int|false <p> |
||
4543 | * Return the numeric position of the first occurrence of needle in the haystack string,<br> |
||
4544 | * or false if needle is not found. |
||
4545 | * </p> |
||
4546 | */ |
||
4547 | 10 | public static function stripos(string $haystack, string $needle, int $offset = 0, string $encoding = 'UTF-8', bool $cleanUtf8 = false) |
|
4579 | |||
4580 | /** |
||
4581 | * Returns all of haystack starting from and including the first occurrence of needle to the end. |
||
4582 | * |
||
4583 | * @param string $haystack <p>The input string. Must be valid UTF-8.</p> |
||
4584 | * @param string $needle <p>The string to look for. Must be valid UTF-8.</p> |
||
4585 | * @param bool $before_needle [optional] <p> |
||
4586 | * If <b>TRUE</b>, grapheme_strstr() returns the part of the |
||
4587 | * haystack before the first occurrence of the needle (excluding the needle). |
||
4588 | * </p> |
||
4589 | * @param string $encoding [optional] <p>Set the charset for e.g. "\mb_" function</p> |
||
4590 | * @param bool $cleanUtf8 [optional] <p>Remove non UTF-8 chars from the string.</p> |
||
4591 | * |
||
4592 | * @return false|string A sub-string,<br>or <strong>false</strong> if needle is not found. |
||
4593 | */ |
||
4594 | 17 | public static function stristr(string $haystack, string $needle, bool $before_needle = false, string $encoding = 'UTF-8', bool $cleanUtf8 = false) |
|
4655 | |||
4656 | /** |
||
4657 | * Get the string length, not the byte-length! |
||
4658 | * |
||
4659 | * @link http://php.net/manual/en/function.mb-strlen.php |
||
4660 | * |
||
4661 | * @param string $str <p>The string being checked for length.</p> |
||
4662 | * @param string $encoding [optional] <p>Set the charset.</p> |
||
4663 | * @param bool $cleanUtf8 [optional] <p>Remove non UTF-8 chars from the string.</p> |
||
4664 | * |
||
4665 | * @return int <p>The number of characters in the string $str having character encoding $encoding. (One multi-byte |
||
4666 | * character counted as +1)</p> |
||
4667 | */ |
||
4668 | 85 | public static function strlen(string $str, string $encoding = 'UTF-8', bool $cleanUtf8 = false): int |
|
4761 | |||
4762 | /** |
||
4763 | * Get string length in byte. |
||
4764 | * |
||
4765 | * @param string $str |
||
4766 | * |
||
4767 | * @return int |
||
4768 | */ |
||
4769 | 72 | public static function strlen_in_byte(string $str): int |
|
4779 | |||
4780 | /** |
||
4781 | * Case insensitive string comparisons using a "natural order" algorithm. |
||
4782 | * |
||
4783 | * INFO: natural order version of UTF8::strcasecmp() |
||
4784 | * |
||
4785 | * @param string $str1 <p>The first string.</p> |
||
4786 | * @param string $str2 <p>The second string.</p> |
||
4787 | * |
||
4788 | * @return int <strong>< 0</strong> if str1 is less than str2<br> |
||
4789 | * <strong>> 0</strong> if str1 is greater than str2<br> |
||
4790 | * <strong>0</strong> if they are equal |
||
4791 | */ |
||
4792 | 1 | public static function strnatcasecmp(string $str1, string $str2): int |
|
4796 | |||
4797 | /** |
||
4798 | * String comparisons using a "natural order" algorithm |
||
4799 | * |
||
4800 | * INFO: natural order version of UTF8::strcmp() |
||
4801 | * |
||
4802 | * @link http://php.net/manual/en/function.strnatcmp.php |
||
4803 | * |
||
4804 | * @param string $str1 <p>The first string.</p> |
||
4805 | * @param string $str2 <p>The second string.</p> |
||
4806 | * |
||
4807 | * @return int <strong>< 0</strong> if str1 is less than str2;<br> |
||
4808 | * <strong>> 0</strong> if str1 is greater than str2;<br> |
||
4809 | * <strong>0</strong> if they are equal |
||
4810 | */ |
||
4811 | 2 | public static function strnatcmp(string $str1, string $str2): int |
|
4815 | |||
4816 | /** |
||
4817 | * Case-insensitive string comparison of the first n characters. |
||
4818 | * |
||
4819 | * @link http://php.net/manual/en/function.strncasecmp.php |
||
4820 | * |
||
4821 | * @param string $str1 <p>The first string.</p> |
||
4822 | * @param string $str2 <p>The second string.</p> |
||
4823 | * @param int $len <p>The length of strings to be used in the comparison.</p> |
||
4824 | * |
||
4825 | * @return int <strong>< 0</strong> if <i>str1</i> is less than <i>str2</i>;<br> |
||
4826 | * <strong>> 0</strong> if <i>str1</i> is greater than <i>str2</i>;<br> |
||
4827 | * <strong>0</strong> if they are equal |
||
4828 | */ |
||
4829 | 1 | public static function strncasecmp(string $str1, string $str2, int $len): int |
|
4833 | |||
4834 | /** |
||
4835 | * String comparison of the first n characters. |
||
4836 | * |
||
4837 | * @link http://php.net/manual/en/function.strncmp.php |
||
4838 | * |
||
4839 | * @param string $str1 <p>The first string.</p> |
||
4840 | * @param string $str2 <p>The second string.</p> |
||
4841 | * @param int $len <p>Number of characters to use in the comparison.</p> |
||
4842 | * |
||
4843 | * @return int <strong>< 0</strong> if <i>str1</i> is less than <i>str2</i>;<br> |
||
4844 | * <strong>> 0</strong> if <i>str1</i> is greater than <i>str2</i>;<br> |
||
4845 | * <strong>0</strong> if they are equal |
||
4846 | */ |
||
4847 | 2 | public static function strncmp(string $str1, string $str2, int $len): int |
|
4854 | |||
4855 | /** |
||
4856 | * Search a string for any of a set of characters. |
||
4857 | * |
||
4858 | * @link http://php.net/manual/en/function.strpbrk.php |
||
4859 | * |
||
4860 | * @param string $haystack <p>The string where char_list is looked for.</p> |
||
4861 | * @param string $char_list <p>This parameter is case sensitive.</p> |
||
4862 | * |
||
4863 | * @return string|false <p>String starting from the character found, or false if it is not found.</p> |
||
4864 | */ |
||
4865 | 1 | public static function strpbrk(string $haystack, string $char_list) |
|
4877 | |||
4878 | /** |
||
4879 | * Find position of first occurrence of string in a string. |
||
4880 | * |
||
4881 | * @link http://php.net/manual/en/function.mb-strpos.php |
||
4882 | * |
||
4883 | * @param string $haystack <p>The string from which to get the position of the first occurrence of needle.</p> |
||
4884 | * @param string $needle <p>The string to find in haystack.</p> |
||
4885 | * @param int $offset [optional] <p>The search offset. If it is not specified, 0 is used.</p> |
||
4886 | * @param string $encoding [optional] <p>Set the charset.</p> |
||
4887 | * @param bool $cleanUtf8 [optional] <p>Remove non UTF-8 chars from the string.</p> |
||
4888 | * |
||
4889 | * @return int|false <p> |
||
4890 | * The numeric position of the first occurrence of needle in the haystack string.<br> |
||
4891 | * If needle is not found it returns false. |
||
4892 | * </p> |
||
4893 | */ |
||
4894 | 59 | public static function strpos(string $haystack, string $needle, int $offset = 0, string $encoding = 'UTF-8', bool $cleanUtf8 = false) |
|
5017 | |||
5018 | /** |
||
5019 | * Finds the last occurrence of a character in a string within another. |
||
5020 | * |
||
5021 | * @link http://php.net/manual/en/function.mb-strrchr.php |
||
5022 | * |
||
5023 | * @param string $haystack <p>The string from which to get the last occurrence of needle.</p> |
||
5024 | * @param string $needle <p>The string to find in haystack</p> |
||
5025 | * @param bool $before_needle [optional] <p> |
||
5026 | * Determines which portion of haystack |
||
5027 | * this function returns. |
||
5028 | * If set to true, it returns all of haystack |
||
5029 | * from the beginning to the last occurrence of needle. |
||
5030 | * If set to false, it returns all of haystack |
||
5031 | * from the last occurrence of needle to the end, |
||
5032 | * </p> |
||
5033 | * @param string $encoding [optional] <p> |
||
5034 | * Character encoding name to use. |
||
5035 | * If it is omitted, internal character encoding is used. |
||
5036 | * </p> |
||
5037 | * @param bool $cleanUtf8 [optional] <p>Remove non UTF-8 chars from the string.</p> |
||
5038 | * |
||
5039 | * @return string|false The portion of haystack or false if needle is not found. |
||
5040 | */ |
||
5041 | 1 | View Code Duplication | public static function strrchr(string $haystack, string $needle, bool $before_needle = false, string $encoding = 'UTF-8', bool $cleanUtf8 = false) |
5057 | |||
5058 | /** |
||
5059 | * Reverses characters order in the string. |
||
5060 | * |
||
5061 | * @param string $str The input string |
||
5062 | * |
||
5063 | * @return string The string with characters in the reverse sequence |
||
5064 | */ |
||
5065 | 4 | public static function strrev(string $str): string |
|
5073 | |||
5074 | /** |
||
5075 | * Finds the last occurrence of a character in a string within another, case insensitive. |
||
5076 | * |
||
5077 | * @link http://php.net/manual/en/function.mb-strrichr.php |
||
5078 | * |
||
5079 | * @param string $haystack <p>The string from which to get the last occurrence of needle.</p> |
||
5080 | * @param string $needle <p>The string to find in haystack.</p> |
||
5081 | * @param bool $before_needle [optional] <p> |
||
5082 | * Determines which portion of haystack |
||
5083 | * this function returns. |
||
5084 | * If set to true, it returns all of haystack |
||
5085 | * from the beginning to the last occurrence of needle. |
||
5086 | * If set to false, it returns all of haystack |
||
5087 | * from the last occurrence of needle to the end, |
||
5088 | * </p> |
||
5089 | * @param string $encoding [optional] <p> |
||
5090 | * Character encoding name to use. |
||
5091 | * If it is omitted, internal character encoding is used. |
||
5092 | * </p> |
||
5093 | * @param bool $cleanUtf8 [optional] <p>Remove non UTF-8 chars from the string.</p> |
||
5094 | * |
||
5095 | * @return string|false <p>The portion of haystack or<br>false if needle is not found.</p> |
||
5096 | */ |
||
5097 | 1 | View Code Duplication | public static function strrichr(string $haystack, string $needle, bool $before_needle = false, string $encoding = 'UTF-8', bool $cleanUtf8 = false) |
5112 | |||
5113 | /** |
||
5114 | * Find position of last occurrence of a case-insensitive string. |
||
5115 | * |
||
5116 | * @param string $haystack <p>The string to look in.</p> |
||
5117 | * @param string $needle <p>The string to look for.</p> |
||
5118 | * @param int $offset [optional] <p>Number of characters to ignore in the beginning or end.</p> |
||
5119 | * @param string $encoding [optional] <p>Set the charset.</p> |
||
5120 | * @param bool $cleanUtf8 [optional] <p>Remove non UTF-8 chars from the string.</p> |
||
5121 | * |
||
5122 | * @return int|false <p> |
||
5123 | * The numeric position of the last occurrence of needle in the haystack string.<br>If needle is |
||
5124 | * not found, it returns false. |
||
5125 | * </p> |
||
5126 | */ |
||
5127 | 1 | public static function strripos(string $haystack, string $needle, int $offset = 0, string $encoding = 'UTF-8', bool $cleanUtf8 = false) |
|
5175 | |||
5176 | /** |
||
5177 | * Find position of last occurrence of a string in a string. |
||
5178 | * |
||
5179 | * @link http://php.net/manual/en/function.mb-strrpos.php |
||
5180 | * |
||
5181 | * @param string $haystack <p>The string being checked, for the last occurrence of needle</p> |
||
5182 | * @param string|int $needle <p>The string to find in haystack.<br>Or a code point as int.</p> |
||
5183 | * @param int $offset [optional] <p>May be specified to begin searching an arbitrary number of characters |
||
5184 | * into the string. Negative values will stop searching at an arbitrary point prior to |
||
5185 | * the end of the string. |
||
5186 | * </p> |
||
5187 | * @param string $encoding [optional] <p>Set the charset.</p> |
||
5188 | * @param bool $cleanUtf8 [optional] <p>Remove non UTF-8 chars from the string.</p> |
||
5189 | * |
||
5190 | * @return int|false <p>The numeric position of the last occurrence of needle in the haystack string.<br>If needle |
||
5191 | * is not found, it returns false.</p> |
||
5192 | */ |
||
5193 | 10 | public static function strrpos(string $haystack, $needle, int $offset = null, string $encoding = 'UTF-8', bool $cleanUtf8 = false) |
|
5266 | |||
5267 | /** |
||
5268 | * Finds the length of the initial segment of a string consisting entirely of characters contained within a given |
||
5269 | * mask. |
||
5270 | * |
||
5271 | * @param string $str <p>The input string.</p> |
||
5272 | * @param string $mask <p>The mask of chars</p> |
||
5273 | * @param int $offset [optional] |
||
5274 | * @param int $length [optional] |
||
5275 | * |
||
5276 | * @return int |
||
5277 | */ |
||
5278 | 10 | public static function strspn(string $str, string $mask, int $offset = 0, int $length = null): int |
|
5294 | |||
5295 | /** |
||
5296 | * Returns part of haystack string from the first occurrence of needle to the end of haystack. |
||
5297 | * |
||
5298 | * @param string $haystack <p>The input string. Must be valid UTF-8.</p> |
||
5299 | * @param string $needle <p>The string to look for. Must be valid UTF-8.</p> |
||
5300 | * @param bool $before_needle [optional] <p> |
||
5301 | * If <b>TRUE</b>, strstr() returns the part of the |
||
5302 | * haystack before the first occurrence of the needle (excluding the needle). |
||
5303 | * </p> |
||
5304 | * @param string $encoding [optional] <p>Set the charset.</p> |
||
5305 | * @param bool $cleanUtf8 [optional] <p>Remove non UTF-8 chars from the string.</p> |
||
5306 | * |
||
5307 | * @return string|false A sub-string,<br>or <strong>false</strong> if needle is not found. |
||
5308 | */ |
||
5309 | 2 | public static function strstr(string $haystack, string $needle, bool $before_needle = false, $encoding = 'UTF-8', $cleanUtf8 = false) |
|
5362 | |||
5363 | /** |
||
5364 | * Unicode transformation for case-less matching. |
||
5365 | * |
||
5366 | * @link http://unicode.org/reports/tr21/tr21-5.html |
||
5367 | * |
||
5368 | * @param string $str <p>The input string.</p> |
||
5369 | * @param bool $full [optional] <p> |
||
5370 | * <b>true</b>, replace full case folding chars (default)<br> |
||
5371 | * <b>false</b>, use only limited static array [UTF8::$commonCaseFold] |
||
5372 | * </p> |
||
5373 | * @param bool $cleanUtf8 [optional] <p>Remove non UTF-8 chars from the string.</p> |
||
5374 | * |
||
5375 | * @return string |
||
5376 | */ |
||
5377 | 13 | public static function strtocasefold(string $str, bool $full = true, bool $cleanUtf8 = false): string |
|
5409 | |||
5410 | /** |
||
5411 | * Make a string lowercase. |
||
5412 | * |
||
5413 | * @link http://php.net/manual/en/function.mb-strtolower.php |
||
5414 | * |
||
5415 | * @param string $str <p>The string being lowercased.</p> |
||
5416 | * @param string $encoding [optional] <p>Set the charset for e.g. "\mb_" function</p> |
||
5417 | * @param bool $cleanUtf8 [optional] <p>Remove non UTF-8 chars from the string.</p> |
||
5418 | * @param string|null $lang [optional] <p>Set the language for special cases: az, el, lt, tr</p> |
||
5419 | * |
||
5420 | * @return string str with all alphabetic characters converted to lowercase. |
||
5421 | */ |
||
5422 | 25 | View Code Duplication | public static function strtolower($str, string $encoding = 'UTF-8', bool $cleanUtf8 = false, string $lang = null): string |
5463 | |||
5464 | /** |
||
5465 | * Generic case sensitive transformation for collation matching. |
||
5466 | * |
||
5467 | * @param string $str <p>The input string</p> |
||
5468 | * |
||
5469 | * @return string |
||
5470 | */ |
||
5471 | 3 | private static function strtonatfold(string $str): string |
|
5476 | |||
5477 | /** |
||
5478 | * Make a string uppercase. |
||
5479 | * |
||
5480 | * @link http://php.net/manual/en/function.mb-strtoupper.php |
||
5481 | * |
||
5482 | * @param string $str <p>The string being uppercased.</p> |
||
5483 | * @param string $encoding [optional] <p>Set the charset.</p> |
||
5484 | * @param bool $cleanUtf8 [optional] <p>Remove non UTF-8 chars from the string.</p> |
||
5485 | * @param string|null $lang [optional] <p>Set the language for special cases: az, el, lt, tr</p> |
||
5486 | * |
||
5487 | * @return string <p>$str with all alphabetic characters converted to uppercase.</p> |
||
5488 | */ |
||
5489 | 19 | View Code Duplication | public static function strtoupper($str, string $encoding = 'UTF-8', bool $cleanUtf8 = false, string $lang = null): string |
5529 | |||
5530 | /** |
||
5531 | * Translate characters or replace sub-strings. |
||
5532 | * |
||
5533 | * @link http://php.net/manual/en/function.strtr.php |
||
5534 | * |
||
5535 | * @param string $str <p>The string being translated.</p> |
||
5536 | * @param string|string[] $from <p>The string replacing from.</p> |
||
5537 | * @param string|string[] $to <p>The string being translated to to.</p> |
||
5538 | * |
||
5539 | * @return string <p> |
||
5540 | * This function returns a copy of str, translating all occurrences of each character in from to the |
||
5541 | * corresponding character in to. |
||
5542 | * </p> |
||
5543 | */ |
||
5544 | 1 | public static function strtr(string $str, $from, $to = INF): string |
|
5575 | |||
5576 | /** |
||
5577 | * Return the width of a string. |
||
5578 | * |
||
5579 | * @param string $str <p>The input string.</p> |
||
5580 | * @param string $encoding [optional] <p>Default is UTF-8</p> |
||
5581 | * @param bool $cleanUtf8 [optional] <p>Remove non UTF-8 chars from the string.</p> |
||
5582 | * |
||
5583 | * @return int |
||
5584 | */ |
||
5585 | 1 | View Code Duplication | public static function strwidth(string $str, string $encoding = 'UTF-8', bool $cleanUtf8 = false): int |
5600 | |||
5601 | /** |
||
5602 | * Get part of a string. |
||
5603 | * |
||
5604 | * @link http://php.net/manual/en/function.mb-substr.php |
||
5605 | * |
||
5606 | * @param string $str <p>The string being checked.</p> |
||
5607 | * @param int $offset <p>The first position used in str.</p> |
||
5608 | * @param int $length [optional] <p>The maximum length of the returned string.</p> |
||
5609 | * @param string $encoding [optional] <p>Default is UTF-8</p> |
||
5610 | * @param bool $cleanUtf8 [optional] <p>Remove non UTF-8 chars from the string.</p> |
||
5611 | * |
||
5612 | * @return string|false <p>The portion of <i>str</i> specified by the <i>offset</i> and |
||
5613 | * <i>length</i> parameters.</p><p>If <i>str</i> is shorter than <i>offset</i> |
||
5614 | * characters long, <b>FALSE</b> will be returned.</p> |
||
5615 | */ |
||
5616 | 71 | public static function substr(string $str, int $offset = 0, int $length = null, string $encoding = 'UTF-8', bool $cleanUtf8 = false) |
|
5720 | |||
5721 | /** |
||
5722 | * Binary safe comparison of two strings from an offset, up to length characters. |
||
5723 | * |
||
5724 | * @param string $str1 <p>The main string being compared.</p> |
||
5725 | * @param string $str2 <p>The secondary string being compared.</p> |
||
5726 | * @param int $offset [optional] <p>The start position for the comparison. If negative, it starts |
||
5727 | * counting from the end of the string.</p> |
||
5728 | * @param int|null $length [optional] <p>The length of the comparison. The default value is the largest of |
||
5729 | * the length of the str compared to the length of main_str less the offset.</p> |
||
5730 | * @param bool $case_insensitivity [optional] <p>If case_insensitivity is TRUE, comparison is case |
||
5731 | * insensitive.</p> |
||
5732 | * |
||
5733 | * @return int <p> |
||
5734 | * <strong>< 0</strong> if str1 is less than str2;<br> |
||
5735 | * <strong>> 0</strong> if str1 is greater than str2,<br> |
||
5736 | * <strong>0</strong> if they are equal. |
||
5737 | * </p> |
||
5738 | */ |
||
5739 | 1 | public static function substr_compare(string $str1, string $str2, int $offset = 0, int $length = null, bool $case_insensitivity = false): int |
|
5765 | |||
5766 | /** |
||
5767 | * Count the number of substring occurrences. |
||
5768 | * |
||
5769 | * @link http://php.net/manual/en/function.substr-count.php |
||
5770 | * |
||
5771 | * @param string $haystack <p>The string to search in.</p> |
||
5772 | * @param string $needle <p>The substring to search for.</p> |
||
5773 | * @param int $offset [optional] <p>The offset where to start counting.</p> |
||
5774 | * @param int $length [optional] <p> |
||
5775 | * The maximum length after the specified offset to search for the |
||
5776 | * substring. It outputs a warning if the offset plus the length is |
||
5777 | * greater than the haystack length. |
||
5778 | * </p> |
||
5779 | * @param string $encoding <p>Set the charset.</p> |
||
5780 | * @param bool $cleanUtf8 [optional] <p>Remove non UTF-8 chars from the string.</p> |
||
5781 | * |
||
5782 | * @return int|false <p>This functions returns an integer or false if there isn't a string.</p> |
||
5783 | */ |
||
5784 | 1 | public static function substr_count(string $haystack, string $needle, int $offset = 0, int $length = null, string $encoding = 'UTF-8', bool $cleanUtf8 = false) |
|
5848 | |||
5849 | /** |
||
5850 | * Removes an prefix ($needle) from start of the string ($haystack), case insensitive. |
||
5851 | * |
||
5852 | * @param string $haystack <p>The string to search in.</p> |
||
5853 | * @param string $needle <p>The substring to search for.</p> |
||
5854 | * |
||
5855 | * @return string <p>Return the sub-string.</p> |
||
5856 | */ |
||
5857 | 1 | View Code Duplication | public static function substr_ileft(string $haystack, string $needle): string |
5877 | |||
5878 | /** |
||
5879 | * Removes an suffix ($needle) from end of the string ($haystack), case insensitive. |
||
5880 | * |
||
5881 | * @param string $haystack <p>The string to search in.</p> |
||
5882 | * @param string $needle <p>The substring to search for.</p> |
||
5883 | * |
||
5884 | * @return string <p>Return the sub-string.</p> |
||
5885 | */ |
||
5886 | 1 | View Code Duplication | public static function substr_iright(string $haystack, string $needle): string |
5906 | |||
5907 | /** |
||
5908 | * Removes an prefix ($needle) from start of the string ($haystack). |
||
5909 | * |
||
5910 | * @param string $haystack <p>The string to search in.</p> |
||
5911 | * @param string $needle <p>The substring to search for.</p> |
||
5912 | * |
||
5913 | * @return string <p>Return the sub-string.</p> |
||
5914 | */ |
||
5915 | 1 | View Code Duplication | public static function substr_left(string $haystack, string $needle): string |
5935 | |||
5936 | /** |
||
5937 | * Replace text within a portion of a string. |
||
5938 | * |
||
5939 | * source: https://gist.github.com/stemar/8287074 |
||
5940 | * |
||
5941 | * @param string|string[] $str <p>The input string or an array of stings.</p> |
||
5942 | * @param string|string[] $replacement <p>The replacement string or an array of stings.</p> |
||
5943 | * @param int|int[] $offset <p> |
||
5944 | * If start is positive, the replacing will begin at the start'th offset |
||
5945 | * into string. |
||
5946 | * <br><br> |
||
5947 | * If start is negative, the replacing will begin at the start'th character |
||
5948 | * from the end of string. |
||
5949 | * </p> |
||
5950 | * @param int|int[]|null $length [optional] <p>If given and is positive, it represents the length of the |
||
5951 | * portion of string which is to be replaced. If it is negative, it |
||
5952 | * represents the number of characters from the end of string at which to |
||
5953 | * stop replacing. If it is not given, then it will default to strlen( |
||
5954 | * string ); i.e. end the replacing at the end of string. Of course, if |
||
5955 | * length is zero then this function will have the effect of inserting |
||
5956 | * replacement into string at the given start offset.</p> |
||
5957 | * |
||
5958 | * @return string|string[] <p>The result string is returned. If string is an array then array is returned.</p> |
||
5959 | */ |
||
5960 | 7 | public static function substr_replace($str, $replacement, $offset, $length = null) |
|
6037 | |||
6038 | /** |
||
6039 | * Removes an suffix ($needle) from end of the string ($haystack). |
||
6040 | * |
||
6041 | * @param string $haystack <p>The string to search in.</p> |
||
6042 | * @param string $needle <p>The substring to search for.</p> |
||
6043 | * |
||
6044 | * @return string <p>Return the sub-string.</p> |
||
6045 | */ |
||
6046 | 1 | View Code Duplication | public static function substr_right(string $haystack, string $needle): string |
6066 | |||
6067 | /** |
||
6068 | * Returns a case swapped version of the string. |
||
6069 | * |
||
6070 | * @param string $str <p>The input string.</p> |
||
6071 | * @param string $encoding [optional] <p>Default is UTF-8</p> |
||
6072 | * @param bool $cleanUtf8 [optional] <p>Remove non UTF-8 chars from the string.</p> |
||
6073 | * |
||
6074 | * @return string <p>Each character's case swapped.</p> |
||
6075 | */ |
||
6076 | 1 | public static function swapCase(string $str, string $encoding = 'UTF-8', bool $cleanUtf8 = false): string |
|
6108 | |||
6109 | /** |
||
6110 | * alias for "UTF8::to_ascii()" |
||
6111 | * |
||
6112 | * @see UTF8::to_ascii() |
||
6113 | * |
||
6114 | * @param string $str |
||
6115 | * @param string $subst_chr |
||
6116 | * @param bool $strict |
||
6117 | * |
||
6118 | * @return string |
||
6119 | * |
||
6120 | * @deprecated <p>use "UTF8::to_ascii()"</p> |
||
6121 | */ |
||
6122 | 7 | public static function toAscii(string $str, string $subst_chr = '?', bool $strict = false): string |
|
6126 | |||
6127 | /** |
||
6128 | * alias for "UTF8::to_iso8859()" |
||
6129 | * |
||
6130 | * @see UTF8::to_iso8859() |
||
6131 | * |
||
6132 | * @param string|string[] $str |
||
6133 | * |
||
6134 | * @return string|string[] |
||
6135 | * |
||
6136 | * @deprecated <p>use "UTF8::to_iso8859()"</p> |
||
6137 | */ |
||
6138 | 1 | public static function toIso8859($str) |
|
6142 | |||
6143 | /** |
||
6144 | * alias for "UTF8::to_latin1()" |
||
6145 | * |
||
6146 | * @see UTF8::to_latin1() |
||
6147 | * |
||
6148 | * @param string|string[] $str |
||
6149 | * |
||
6150 | * @return string|string[] |
||
6151 | * |
||
6152 | * @deprecated <p>use "UTF8::to_latin1()"</p> |
||
6153 | */ |
||
6154 | 1 | public static function toLatin1($str) |
|
6158 | |||
6159 | /** |
||
6160 | * alias for "UTF8::to_utf8()" |
||
6161 | * |
||
6162 | * @see UTF8::to_utf8() |
||
6163 | * |
||
6164 | * @param string|string[] $str |
||
6165 | * |
||
6166 | * @return string|string[] |
||
6167 | * |
||
6168 | * @deprecated <p>use "UTF8::to_utf8()"</p> |
||
6169 | */ |
||
6170 | 1 | public static function toUTF8($str) |
|
6174 | |||
6175 | /** |
||
6176 | * Convert a string into ASCII. |
||
6177 | * |
||
6178 | * @param string $str <p>The input string.</p> |
||
6179 | * @param string $unknown [optional] <p>Character use if character unknown. (default is ?)</p> |
||
6180 | * @param bool $strict [optional] <p>Use "transliterator_transliterate()" from PHP-Intl | WARNING: bad |
||
6181 | * performance</p> |
||
6182 | * |
||
6183 | * @return string |
||
6184 | */ |
||
6185 | 21 | public static function to_ascii(string $str, string $unknown = '?', bool $strict = false): string |
|
6334 | |||
6335 | /** |
||
6336 | * Convert a string into "ISO-8859"-encoding (Latin-1). |
||
6337 | * |
||
6338 | * @param string|string[] $str |
||
6339 | * |
||
6340 | * @return string|string[] |
||
6341 | */ |
||
6342 | 3 | public static function to_iso8859($str) |
|
6359 | |||
6360 | /** |
||
6361 | * alias for "UTF8::to_iso8859()" |
||
6362 | * |
||
6363 | * @see UTF8::to_iso8859() |
||
6364 | * |
||
6365 | * @param string|string[] $str |
||
6366 | * |
||
6367 | * @return string|string[] |
||
6368 | */ |
||
6369 | 1 | public static function to_latin1($str) |
|
6373 | |||
6374 | /** |
||
6375 | * This function leaves UTF-8 characters alone, while converting almost all non-UTF8 to UTF8. |
||
6376 | * |
||
6377 | * <ul> |
||
6378 | * <li>It decode UTF-8 codepoints and unicode escape sequences.</li> |
||
6379 | * <li>It assumes that the encoding of the original string is either WINDOWS-1252 or ISO-8859.</li> |
||
6380 | * <li>WARNING: It does not remove invalid UTF-8 characters, so you maybe need to use "UTF8::clean()" for this |
||
6381 | * case.</li> |
||
6382 | * </ul> |
||
6383 | * |
||
6384 | * @param string|string[] $str <p>Any string or array.</p> |
||
6385 | * @param bool $decodeHtmlEntityToUtf8 <p>Set to true, if you need to decode html-entities.</p> |
||
6386 | * |
||
6387 | * @return string|string[] <p>The UTF-8 encoded string.</p> |
||
6388 | */ |
||
6389 | 22 | public static function to_utf8($str, bool $decodeHtmlEntityToUtf8 = false) |
|
6482 | |||
6483 | /** |
||
6484 | * @param int $int |
||
6485 | * |
||
6486 | * @return string |
||
6487 | */ |
||
6488 | 16 | private static function to_utf8_convert($int): string |
|
6516 | |||
6517 | /** |
||
6518 | * Strip whitespace or other characters from beginning or end of a UTF-8 string. |
||
6519 | * |
||
6520 | * INFO: This is slower then "trim()" |
||
6521 | * |
||
6522 | * We can only use the original-function, if we use <= 7-Bit in the string / chars |
||
6523 | * but the check for ACSII (7-Bit) cost more time, then we can safe here. |
||
6524 | * |
||
6525 | * @param string $str <p>The string to be trimmed</p> |
||
6526 | * @param mixed $chars [optional] <p>Optional characters to be stripped</p> |
||
6527 | * |
||
6528 | * @return string <p>The trimmed string.</p> |
||
6529 | */ |
||
6530 | 26 | public static function trim(string $str = '', $chars = INF): string |
|
6543 | |||
6544 | /** |
||
6545 | * Makes string's first char uppercase. |
||
6546 | * |
||
6547 | * @param string $str <p>The input string.</p> |
||
6548 | * @param string $encoding [optional] <p>Set the charset.</p> |
||
6549 | * @param bool $cleanUtf8 [optional] <p>Remove non UTF-8 chars from the string.</p> |
||
6550 | * |
||
6551 | * @return string <p>The resulting string</p> |
||
6552 | */ |
||
6553 | 14 | public static function ucfirst(string $str, string $encoding = 'UTF-8', bool $cleanUtf8 = false): string |
|
6574 | |||
6575 | /** |
||
6576 | * alias for "UTF8::ucfirst()" |
||
6577 | * |
||
6578 | * @see UTF8::ucfirst() |
||
6579 | * |
||
6580 | * @param string $word |
||
6581 | * @param string $encoding |
||
6582 | * @param bool $cleanUtf8 |
||
6583 | * |
||
6584 | * @return string |
||
6585 | */ |
||
6586 | 1 | public static function ucword(string $word, string $encoding = 'UTF-8', bool $cleanUtf8 = false): string |
|
6590 | |||
6591 | /** |
||
6592 | * Uppercase for all words in the string. |
||
6593 | * |
||
6594 | * @param string $str <p>The input string.</p> |
||
6595 | * @param string[] $exceptions [optional] <p>Exclusion for some words.</p> |
||
6596 | * @param string $charlist [optional] <p>Additional chars that contains to words and do not start a new word.</p> |
||
6597 | * @param string $encoding [optional] <p>Set the charset.</p> |
||
6598 | * @param bool $cleanUtf8 [optional] <p>Remove non UTF-8 chars from the string.</p> |
||
6599 | * |
||
6600 | * @return string |
||
6601 | */ |
||
6602 | 8 | public static function ucwords(string $str, array $exceptions = [], string $charlist = '', string $encoding = 'UTF-8', bool $cleanUtf8 = false): string |
|
6659 | |||
6660 | /** |
||
6661 | * Multi decode html entity & fix urlencoded-win1252-chars. |
||
6662 | * |
||
6663 | * e.g: |
||
6664 | * 'test+test' => 'test test' |
||
6665 | * 'Düsseldorf' => 'Düsseldorf' |
||
6666 | * 'D%FCsseldorf' => 'Düsseldorf' |
||
6667 | * 'Düsseldorf' => 'Düsseldorf' |
||
6668 | * 'D%26%23xFC%3Bsseldorf' => 'Düsseldorf' |
||
6669 | * 'Düsseldorf' => 'Düsseldorf' |
||
6670 | * 'D%C3%BCsseldorf' => 'Düsseldorf' |
||
6671 | * 'D%C3%83%C2%BCsseldorf' => 'Düsseldorf' |
||
6672 | * 'D%25C3%2583%25C2%25BCsseldorf' => 'Düsseldorf' |
||
6673 | * |
||
6674 | * @param string $str <p>The input string.</p> |
||
6675 | * @param bool $multi_decode <p>Decode as often as possible.</p> |
||
6676 | * |
||
6677 | * @return string |
||
6678 | */ |
||
6679 | 1 | View Code Duplication | public static function urldecode(string $str, bool $multi_decode = true): string |
6708 | |||
6709 | /** |
||
6710 | * Return a array with "urlencoded"-win1252 -> UTF-8 |
||
6711 | * |
||
6712 | * @deprecated <p>use the "UTF8::urldecode()" function to decode a string</p> |
||
6713 | * |
||
6714 | * @return array |
||
6715 | */ |
||
6716 | 1 | public static function urldecode_fix_win1252_chars(): array |
|
6945 | |||
6946 | /** |
||
6947 | * Decodes an UTF-8 string to ISO-8859-1. |
||
6948 | * |
||
6949 | * @param string $str <p>The input string.</p> |
||
6950 | * @param bool $keepUtf8Chars |
||
6951 | * |
||
6952 | * @return string |
||
6953 | */ |
||
6954 | 6 | public static function utf8_decode(string $str, bool $keepUtf8Chars = false): string |
|
7027 | |||
7028 | /** |
||
7029 | * Encodes an ISO-8859-1 string to UTF-8. |
||
7030 | * |
||
7031 | * @param string $str <p>The input string.</p> |
||
7032 | * |
||
7033 | * @return string |
||
7034 | */ |
||
7035 | 7 | public static function utf8_encode(string $str): string |
|
7068 | |||
7069 | /** |
||
7070 | * fix -> utf8-win1252 chars |
||
7071 | * |
||
7072 | * @param string $str <p>The input string.</p> |
||
7073 | * |
||
7074 | * @return string |
||
7075 | * |
||
7076 | * @deprecated <p>use "UTF8::fix_simple_utf8()"</p> |
||
7077 | */ |
||
7078 | 1 | public static function utf8_fix_win1252_chars(string $str): string |
|
7082 | |||
7083 | /** |
||
7084 | * Returns an array with all utf8 whitespace characters. |
||
7085 | * |
||
7086 | * @see : http://www.bogofilter.org/pipermail/bogofilter/2003-March/001889.html |
||
7087 | * |
||
7088 | * @author: Derek E. [email protected] |
||
7089 | * |
||
7090 | * @return array <p> |
||
7091 | * An array with all known whitespace characters as values and the type of whitespace as keys |
||
7092 | * as defined in above URL. |
||
7093 | * </p> |
||
7094 | */ |
||
7095 | 1 | public static function whitespace_table(): array |
|
7099 | |||
7100 | /** |
||
7101 | * Limit the number of words in a string. |
||
7102 | * |
||
7103 | * @param string $str <p>The input string.</p> |
||
7104 | * @param int $limit <p>The limit of words as integer.</p> |
||
7105 | * @param string $strAddOn <p>Replacement for the striped string.</p> |
||
7106 | * |
||
7107 | * @return string |
||
7108 | */ |
||
7109 | 1 | public static function words_limit(string $str, int $limit = 100, string $strAddOn = '…'): string |
|
7131 | |||
7132 | /** |
||
7133 | * Wraps a string to a given number of characters |
||
7134 | * |
||
7135 | * @link http://php.net/manual/en/function.wordwrap.php |
||
7136 | * |
||
7137 | * @param string $str <p>The input string.</p> |
||
7138 | * @param int $width [optional] <p>The column width.</p> |
||
7139 | * @param string $break [optional] <p>The line is broken using the optional break parameter.</p> |
||
7140 | * @param bool $cut [optional] <p> |
||
7141 | * If the cut is set to true, the string is |
||
7142 | * always wrapped at or before the specified width. So if you have |
||
7143 | * a word that is larger than the given width, it is broken apart. |
||
7144 | * </p> |
||
7145 | * |
||
7146 | * @return string <p>The given string wrapped at the specified column.</p> |
||
7147 | */ |
||
7148 | 10 | public static function wordwrap(string $str, int $width = 75, string $break = "\n", bool $cut = false): string |
|
7196 | |||
7197 | /** |
||
7198 | * Returns an array of Unicode White Space characters. |
||
7199 | * |
||
7200 | * @return array <p>An array with numeric code point as key and White Space Character as value.</p> |
||
7201 | */ |
||
7202 | 1 | public static function ws(): array |
|
7206 | |||
7207 | } |
||
7208 |
According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.
}
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.