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 | 3 | 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 | * Convert binary into an string. |
||
| 254 | * |
||
| 255 | * @param mixed $bin 1|0 |
||
| 256 | * |
||
| 257 | * @return string |
||
| 258 | */ |
||
| 259 | 1 | public static function binary_to_str($bin): string |
|
| 260 | { |
||
| 261 | 1 | if (!isset($bin[0])) { |
|
| 262 | return ''; |
||
| 263 | } |
||
| 264 | |||
| 265 | 1 | $convert = \base_convert($bin, 2, 16); |
|
| 266 | 1 | if ($convert === '0') { |
|
| 267 | 1 | return ''; |
|
| 268 | } |
||
| 269 | |||
| 270 | 1 | return \pack('H*', $convert); |
|
| 271 | } |
||
| 272 | |||
| 273 | /** |
||
| 274 | * Returns the UTF-8 Byte Order Mark Character. |
||
| 275 | * |
||
| 276 | * INFO: take a look at UTF8::$bom for e.g. UTF-16 and UTF-32 BOM values |
||
| 277 | * |
||
| 278 | * @return string UTF-8 Byte Order Mark |
||
| 279 | */ |
||
| 280 | 2 | public static function bom(): string |
|
| 281 | { |
||
| 282 | 2 | return "\xef\xbb\xbf"; |
|
| 283 | } |
||
| 284 | |||
| 285 | /** |
||
| 286 | * @alias of UTF8::chr_map() |
||
| 287 | * |
||
| 288 | * @see UTF8::chr_map() |
||
| 289 | * |
||
| 290 | * @param string|array $callback |
||
| 291 | * @param string $str |
||
| 292 | * |
||
| 293 | * @return array |
||
| 294 | */ |
||
| 295 | 1 | public static function callback($callback, string $str): array |
|
| 296 | { |
||
| 297 | 1 | return self::chr_map($callback, $str); |
|
| 298 | } |
||
| 299 | |||
| 300 | /** |
||
| 301 | * This method will auto-detect your server environment for UTF-8 support. |
||
| 302 | * |
||
| 303 | * INFO: You don't need to run it manually, it will be triggered if it's needed. |
||
| 304 | */ |
||
| 305 | 19 | public static function checkForSupport() |
|
| 306 | { |
||
| 307 | 19 | if (!isset(self::$SUPPORT['already_checked_via_portable_utf8'])) { |
|
| 308 | |||
| 309 | 1 | self::$SUPPORT['already_checked_via_portable_utf8'] = true; |
|
| 310 | |||
| 311 | // http://php.net/manual/en/book.mbstring.php |
||
| 312 | 1 | self::$SUPPORT['mbstring'] = self::mbstring_loaded(); |
|
| 313 | 1 | self::$SUPPORT['mbstring_func_overload'] = self::mbstring_overloaded(); |
|
| 314 | |||
| 315 | // http://php.net/manual/en/book.iconv.php |
||
| 316 | 1 | self::$SUPPORT['iconv'] = self::iconv_loaded(); |
|
| 317 | |||
| 318 | // http://php.net/manual/en/book.intl.php |
||
| 319 | 1 | self::$SUPPORT['intl'] = self::intl_loaded(); |
|
| 320 | 1 | self::$SUPPORT['intl__transliterator_list_ids'] = []; |
|
| 321 | if ( |
||
| 322 | 1 | self::$SUPPORT['intl'] === true |
|
| 323 | && |
||
| 324 | 1 | \function_exists('transliterator_list_ids') === true |
|
| 325 | ) { |
||
| 326 | 1 | self::$SUPPORT['intl__transliterator_list_ids'] = transliterator_list_ids(); |
|
| 327 | } |
||
| 328 | |||
| 329 | // http://php.net/manual/en/class.intlchar.php |
||
| 330 | 1 | self::$SUPPORT['intlChar'] = self::intlChar_loaded(); |
|
| 331 | |||
| 332 | // http://php.net/manual/en/book.pcre.php |
||
| 333 | 1 | self::$SUPPORT['pcre_utf8'] = self::pcre_utf8_support(); |
|
| 334 | } |
||
| 335 | 19 | } |
|
| 336 | |||
| 337 | /** |
||
| 338 | * Generates a UTF-8 encoded character from the given code point. |
||
| 339 | * |
||
| 340 | * INFO: opposite to UTF8::ord() |
||
| 341 | * |
||
| 342 | * @param int|string $code_point <p>The code point for which to generate a character.</p> |
||
| 343 | * @param string $encoding [optional] <p>Default is UTF-8</p> |
||
| 344 | * |
||
| 345 | * @return string|null <p>Multi-Byte character, returns null on failure or empty input.</p> |
||
| 346 | */ |
||
| 347 | 10 | public static function chr($code_point, string $encoding = 'UTF-8') |
|
| 348 | { |
||
| 349 | // init |
||
| 350 | 10 | static $CHAR_CACHE = []; |
|
| 351 | |||
| 352 | 10 | if (!isset(self::$SUPPORT['already_checked_via_portable_utf8'])) { |
|
| 353 | self::checkForSupport(); |
||
| 354 | } |
||
| 355 | |||
| 356 | 10 | if ($encoding !== 'UTF-8') { |
|
| 357 | 2 | $encoding = self::normalize_encoding($encoding, 'UTF-8'); |
|
| 358 | } |
||
| 359 | |||
| 360 | View Code Duplication | if ( |
|
| 361 | 10 | $encoding !== 'UTF-8' |
|
| 362 | && |
||
| 363 | 10 | $encoding !== 'WINDOWS-1252' |
|
| 364 | && |
||
| 365 | 10 | self::$SUPPORT['mbstring'] === false |
|
| 366 | ) { |
||
| 367 | \trigger_error('UTF8::chr() without mbstring cannot handle "' . $encoding . '" encoding', E_USER_WARNING); |
||
| 368 | } |
||
| 369 | |||
| 370 | 10 | $cacheKey = $code_point . $encoding; |
|
| 371 | 10 | if (isset($CHAR_CACHE[$cacheKey]) === true) { |
|
| 372 | 8 | return $CHAR_CACHE[$cacheKey]; |
|
| 373 | } |
||
| 374 | |||
| 375 | 9 | if ($code_point <= 127) { // use "simple"-char only until "\x80" |
|
| 376 | |||
| 377 | 7 | if (self::$CHR === null) { |
|
| 378 | self::$CHR = self::getData('chr'); |
||
| 379 | } |
||
| 380 | |||
| 381 | 7 | $chr = self::$CHR[$code_point]; |
|
| 382 | |||
| 383 | 7 | if ($encoding !== 'UTF-8') { |
|
| 384 | 1 | $chr = \mb_convert_encoding($chr, $encoding, 'UTF-8'); |
|
| 385 | } |
||
| 386 | |||
| 387 | 7 | return $CHAR_CACHE[$cacheKey] = $chr; |
|
| 388 | } |
||
| 389 | |||
| 390 | 7 | if (self::$SUPPORT['intlChar'] === true) { |
|
| 391 | 7 | $chr = \IntlChar::chr($code_point); |
|
| 392 | |||
| 393 | 7 | if ($encoding !== 'UTF-8') { |
|
| 394 | $chr = \mb_convert_encoding($chr, $encoding, 'UTF-8'); |
||
| 395 | } |
||
| 396 | |||
| 397 | 7 | return $CHAR_CACHE[$cacheKey] = $chr; |
|
| 398 | } |
||
| 399 | |||
| 400 | if (self::$CHR === null) { |
||
| 401 | self::$CHR = self::getData('chr'); |
||
| 402 | } |
||
| 403 | |||
| 404 | if ($code_point <= 0x7F) { |
||
| 405 | $chr = self::$CHR[$code_point]; |
||
| 406 | } elseif ($code_point <= 0x7FF) { |
||
| 407 | $chr = self::$CHR[($code_point >> 6) + 0xC0] . |
||
| 408 | self::$CHR[($code_point & 0x3F) + 0x80]; |
||
| 409 | } elseif ($code_point <= 0xFFFF) { |
||
| 410 | $chr = self::$CHR[($code_point >> 12) + 0xE0] . |
||
| 411 | self::$CHR[(($code_point >> 6) & 0x3F) + 0x80] . |
||
| 412 | self::$CHR[($code_point & 0x3F) + 0x80]; |
||
| 413 | } else { |
||
| 414 | $chr = self::$CHR[($code_point >> 18) + 0xF0] . |
||
| 415 | self::$CHR[(($code_point >> 12) & 0x3F) + 0x80] . |
||
| 416 | self::$CHR[(($code_point >> 6) & 0x3F) + 0x80] . |
||
| 417 | self::$CHR[($code_point & 0x3F) + 0x80]; |
||
| 418 | } |
||
| 419 | |||
| 420 | if ($encoding !== 'UTF-8') { |
||
| 421 | $chr = \mb_convert_encoding($chr, $encoding, 'UTF-8'); |
||
| 422 | } |
||
| 423 | |||
| 424 | return $CHAR_CACHE[$cacheKey] = $chr; |
||
| 425 | } |
||
| 426 | |||
| 427 | /** |
||
| 428 | * Applies callback to all characters of a string. |
||
| 429 | * |
||
| 430 | * @param string|array $callback <p>The callback function.</p> |
||
| 431 | * @param string $str <p>UTF-8 string to run callback on.</p> |
||
| 432 | * |
||
| 433 | * @return array <p>The outcome of callback.</p> |
||
| 434 | */ |
||
| 435 | 1 | public static function chr_map($callback, string $str): array |
|
| 436 | { |
||
| 437 | 1 | $chars = self::split($str); |
|
| 438 | |||
| 439 | 1 | return \array_map($callback, $chars); |
|
| 440 | } |
||
| 441 | |||
| 442 | /** |
||
| 443 | * Generates an array of byte length of each character of a Unicode string. |
||
| 444 | * |
||
| 445 | * 1 byte => U+0000 - U+007F |
||
| 446 | * 2 byte => U+0080 - U+07FF |
||
| 447 | * 3 byte => U+0800 - U+FFFF |
||
| 448 | * 4 byte => U+10000 - U+10FFFF |
||
| 449 | * |
||
| 450 | * @param string $str <p>The original unicode string.</p> |
||
| 451 | * |
||
| 452 | * @return array <p>An array of byte lengths of each character.</p> |
||
| 453 | */ |
||
| 454 | 4 | public static function chr_size_list(string $str): array |
|
| 455 | { |
||
| 456 | 4 | if (!isset($str[0])) { |
|
| 457 | 3 | return []; |
|
| 458 | } |
||
| 459 | |||
| 460 | 4 | return \array_map( |
|
| 461 | 4 | function ($data) { |
|
| 462 | 4 | return UTF8::strlen($data, '8BIT'); |
|
| 463 | 4 | }, |
|
| 464 | 4 | self::split($str) |
|
| 465 | ); |
||
| 466 | } |
||
| 467 | |||
| 468 | /** |
||
| 469 | * Get a decimal code representation of a specific character. |
||
| 470 | * |
||
| 471 | * @param string $char <p>The input character.</p> |
||
| 472 | * |
||
| 473 | * @return int |
||
| 474 | */ |
||
| 475 | 2 | public static function chr_to_decimal(string $char): int |
|
| 506 | |||
| 507 | /** |
||
| 508 | * Get hexadecimal code point (U+xxxx) of a UTF-8 encoded character. |
||
| 509 | * |
||
| 510 | * @param string $char <p>The input character</p> |
||
| 511 | * @param string $pfix [optional] |
||
| 512 | * |
||
| 513 | * @return string <p>The code point encoded as U+xxxx<p> |
||
| 514 | */ |
||
| 515 | 1 | public static function chr_to_hex(string $char, string $pfix = 'U+'): string |
|
| 516 | { |
||
| 517 | 1 | if (!isset($char[0])) { |
|
| 518 | 1 | return ''; |
|
| 519 | } |
||
| 520 | |||
| 521 | 1 | if ($char === '�') { |
|
| 522 | 1 | $char = ''; |
|
| 523 | } |
||
| 524 | |||
| 525 | 1 | return self::int_to_hex(self::ord($char), $pfix); |
|
| 526 | } |
||
| 527 | |||
| 528 | /** |
||
| 529 | * alias for "UTF8::chr_to_decimal()" |
||
| 530 | * |
||
| 531 | * @see UTF8::chr_to_decimal() |
||
| 532 | * |
||
| 533 | * @param string $chr |
||
| 534 | * |
||
| 535 | * @return int |
||
| 536 | */ |
||
| 537 | 1 | public static function chr_to_int(string $chr): int |
|
| 538 | { |
||
| 539 | 1 | return self::chr_to_decimal($chr); |
|
| 540 | } |
||
| 541 | |||
| 542 | /** |
||
| 543 | * Splits a string into smaller chunks and multiple lines, using the specified line ending character. |
||
| 544 | * |
||
| 545 | * @param string $body <p>The original string to be split.</p> |
||
| 546 | * @param int $chunklen [optional] <p>The maximum character length of a chunk.</p> |
||
| 547 | * @param string $end [optional] <p>The character(s) to be inserted at the end of each chunk.</p> |
||
| 548 | * |
||
| 549 | * @return string <p>The chunked string</p> |
||
| 550 | */ |
||
| 551 | 1 | public static function chunk_split(string $body, int $chunklen = 76, string $end = "\r\n"): string |
|
| 552 | { |
||
| 553 | 1 | return \implode($end, self::split($body, $chunklen)); |
|
| 554 | } |
||
| 555 | |||
| 556 | /** |
||
| 557 | * Accepts a string and removes all non-UTF-8 characters from it + extras if needed. |
||
| 558 | * |
||
| 559 | * @param string $str <p>The string to be sanitized.</p> |
||
| 560 | * @param bool $remove_bom [optional] <p>Set to true, if you need to remove UTF-BOM.</p> |
||
| 561 | * @param bool $normalize_whitespace [optional] <p>Set to true, if you need to normalize the whitespace.</p> |
||
| 562 | * @param bool $normalize_msword [optional] <p>Set to true, if you need to normalize MS Word chars e.g.: "…" |
||
| 563 | * => "..."</p> |
||
| 564 | * @param bool $keep_non_breaking_space [optional] <p>Set to true, to keep non-breaking-spaces, in combination with |
||
| 565 | * $normalize_whitespace</p> |
||
| 566 | * |
||
| 567 | * @return string <p>Clean UTF-8 encoded string.</p> |
||
| 568 | */ |
||
| 569 | 62 | public static function clean(string $str, bool $remove_bom = false, bool $normalize_whitespace = false, bool $normalize_msword = false, bool $keep_non_breaking_space = false): string |
|
| 570 | { |
||
| 571 | // http://stackoverflow.com/questions/1401317/remove-non-utf8-characters-from-string |
||
| 572 | // caused connection reset problem on larger strings |
||
| 573 | |||
| 574 | 62 | $regx = '/ |
|
| 575 | ( |
||
| 576 | (?: [\x00-\x7F] # single-byte sequences 0xxxxxxx |
||
| 577 | | [\xC0-\xDF][\x80-\xBF] # double-byte sequences 110xxxxx 10xxxxxx |
||
| 578 | | [\xE0-\xEF][\x80-\xBF]{2} # triple-byte sequences 1110xxxx 10xxxxxx * 2 |
||
| 579 | | [\xF0-\xF7][\x80-\xBF]{3} # quadruple-byte sequence 11110xxx 10xxxxxx * 3 |
||
| 580 | ){1,100} # ...one or more times |
||
| 581 | ) |
||
| 582 | | ( [\x80-\xBF] ) # invalid byte in range 10000000 - 10111111 |
||
| 583 | | ( [\xC0-\xFF] ) # invalid byte in range 11000000 - 11111111 |
||
| 584 | /x'; |
||
| 585 | 62 | $str = (string)\preg_replace($regx, '$1', $str); |
|
| 586 | |||
| 587 | 62 | $str = self::replace_diamond_question_mark($str, ''); |
|
| 588 | 62 | $str = self::remove_invisible_characters($str); |
|
| 589 | |||
| 590 | 62 | if ($normalize_whitespace === true) { |
|
| 591 | 37 | $str = self::normalize_whitespace($str, $keep_non_breaking_space); |
|
| 592 | } |
||
| 593 | |||
| 594 | 62 | if ($normalize_msword === true) { |
|
| 595 | 15 | $str = self::normalize_msword($str); |
|
| 596 | } |
||
| 597 | |||
| 598 | 62 | if ($remove_bom === true) { |
|
| 599 | 36 | $str = self::remove_bom($str); |
|
| 600 | } |
||
| 601 | |||
| 602 | 62 | return $str; |
|
| 603 | } |
||
| 604 | |||
| 605 | /** |
||
| 606 | * Clean-up a and show only printable UTF-8 chars at the end + fix UTF-8 encoding. |
||
| 607 | * |
||
| 608 | * @param string $str <p>The input string.</p> |
||
| 609 | * |
||
| 610 | * @return string |
||
| 611 | */ |
||
| 612 | 23 | public static function cleanup(string $str): string |
|
| 613 | { |
||
| 614 | 23 | if (!isset($str[0])) { |
|
| 615 | 2 | return ''; |
|
| 616 | } |
||
| 617 | |||
| 618 | // fixed ISO <-> UTF-8 Errors |
||
| 619 | 23 | $str = self::fix_simple_utf8($str); |
|
| 620 | |||
| 621 | // remove all none UTF-8 symbols |
||
| 622 | // && remove diamond question mark (�) |
||
| 623 | // && remove remove invisible characters (e.g. "\0") |
||
| 624 | // && remove BOM |
||
| 625 | // && normalize whitespace chars (but keep non-breaking-spaces) |
||
| 626 | 23 | $str = self::clean($str, true, true, false, true); |
|
| 627 | |||
| 628 | 23 | return $str; |
|
| 629 | } |
||
| 630 | |||
| 631 | /** |
||
| 632 | * Accepts a string or a array of strings and returns an array of Unicode code points. |
||
| 633 | * |
||
| 634 | * INFO: opposite to UTF8::string() |
||
| 635 | * |
||
| 636 | * @param string|string[] $arg <p>A UTF-8 encoded string or an array of such strings.</p> |
||
| 637 | * @param bool $u_style <p>If True, will return code points in U+xxxx format, |
||
| 638 | * default, code points will be returned as integers.</p> |
||
| 639 | * |
||
| 640 | * @return array <p>The array of code points.</p> |
||
| 641 | */ |
||
| 642 | 7 | public static function codepoints($arg, bool $u_style = false): array |
|
| 668 | |||
| 669 | /** |
||
| 670 | * Returns count of characters used in a string. |
||
| 671 | * |
||
| 672 | * @param string $str <p>The input string.</p> |
||
| 673 | * @param bool $cleanUtf8 [optional] <p>Remove non UTF-8 chars from the string.</p> |
||
| 674 | * |
||
| 675 | * @return array <p>An associative array of Character as keys and |
||
| 676 | * their count as values.</p> |
||
| 677 | */ |
||
| 678 | 7 | public static function count_chars(string $str, bool $cleanUtf8 = false): array |
|
| 679 | { |
||
| 680 | 7 | return \array_count_values(self::split($str, 1, $cleanUtf8)); |
|
| 681 | } |
||
| 682 | |||
| 683 | /** |
||
| 684 | * Converts a int-value into an UTF-8 character. |
||
| 685 | * |
||
| 686 | * @param mixed $int |
||
| 687 | * |
||
| 688 | * @return string |
||
| 689 | */ |
||
| 690 | 5 | public static function decimal_to_chr($int): string |
|
| 691 | { |
||
| 692 | 5 | return self::html_entity_decode('&#' . $int . ';', ENT_QUOTES | ENT_HTML5); |
|
| 693 | } |
||
| 694 | |||
| 695 | /** |
||
| 696 | * Encode a string with a new charset-encoding. |
||
| 697 | * |
||
| 698 | * INFO: The different to "UTF8::utf8_encode()" is that this function, try to fix also broken / double encoding, |
||
| 699 | * so you can call this function also on a UTF-8 String and you don't mess the string. |
||
| 700 | * |
||
| 701 | * @param string $encoding <p>e.g. 'UTF-16', 'UTF-8', 'ISO-8859-1', etc.</p> |
||
| 702 | * @param string $str <p>The input string</p> |
||
| 703 | * @param bool $force [optional] <p>Force the new encoding (we try to fix broken / double encoding for |
||
| 704 | * UTF-8)<br> otherwise we auto-detect the current string-encoding</p> |
||
| 705 | * |
||
| 706 | * @return string |
||
| 707 | */ |
||
| 708 | 13 | public static function encode(string $encoding, string $str, bool $force = true): string |
|
| 709 | { |
||
| 710 | 13 | if (!isset($str[0], $encoding[0])) { |
|
| 711 | 6 | return $str; |
|
| 712 | } |
||
| 713 | |||
| 714 | 13 | if ($encoding !== 'UTF-8') { |
|
| 715 | 2 | $encoding = self::normalize_encoding($encoding, 'UTF-8'); |
|
| 716 | } |
||
| 717 | |||
| 718 | 13 | if (!isset(self::$SUPPORT['already_checked_via_portable_utf8'])) { |
|
| 719 | self::checkForSupport(); |
||
| 720 | } |
||
| 721 | |||
| 722 | 13 | $encodingDetected = self::str_detect_encoding($str); |
|
| 723 | |||
| 724 | if ( |
||
| 725 | 13 | $encodingDetected !== false |
|
| 726 | && |
||
| 727 | ( |
||
| 728 | 13 | $force === true |
|
| 729 | || |
||
| 730 | 13 | $encodingDetected !== $encoding |
|
| 731 | ) |
||
| 732 | ) { |
||
| 733 | |||
| 734 | View Code Duplication | if ( |
|
| 735 | 13 | $encoding === 'UTF-8' |
|
| 736 | && |
||
| 737 | ( |
||
| 738 | 13 | $force === true |
|
| 739 | 3 | || $encodingDetected === 'UTF-8' |
|
| 740 | 3 | || $encodingDetected === 'WINDOWS-1252' |
|
| 741 | 13 | || $encodingDetected === 'ISO-8859-1' |
|
| 742 | ) |
||
| 743 | ) { |
||
| 744 | 11 | return self::to_utf8($str); |
|
| 745 | } |
||
| 746 | |||
| 747 | View Code Duplication | if ( |
|
| 748 | 5 | $encoding === 'ISO-8859-1' |
|
| 749 | && |
||
| 750 | ( |
||
| 751 | 2 | $force === true |
|
| 752 | 1 | || $encodingDetected === 'ISO-8859-1' |
|
| 753 | 1 | || $encodingDetected === 'WINDOWS-1252' |
|
| 754 | 5 | || $encodingDetected === 'UTF-8' |
|
| 755 | ) |
||
| 756 | ) { |
||
| 757 | 2 | return self::to_iso8859($str); |
|
| 758 | } |
||
| 759 | |||
| 760 | View Code Duplication | if ( |
|
| 761 | 4 | $encoding !== 'UTF-8' |
|
| 762 | && |
||
| 763 | 4 | $encoding !== 'WINDOWS-1252' |
|
| 764 | && |
||
| 765 | 4 | self::$SUPPORT['mbstring'] === false |
|
| 766 | ) { |
||
| 767 | \trigger_error('UTF8::encode() without mbstring cannot handle "' . $encoding . '" encoding', E_USER_WARNING); |
||
| 768 | } |
||
| 769 | |||
| 770 | 4 | $strEncoded = \mb_convert_encoding( |
|
| 771 | 4 | $str, |
|
| 772 | 4 | $encoding, |
|
| 773 | 4 | $encodingDetected |
|
| 774 | ); |
||
| 775 | |||
| 776 | 4 | if ($strEncoded) { |
|
| 777 | 4 | return $strEncoded; |
|
| 778 | } |
||
| 779 | } |
||
| 780 | |||
| 781 | 3 | return $str; |
|
| 782 | } |
||
| 783 | |||
| 784 | /** |
||
| 785 | * Reads entire file into a string. |
||
| 786 | * |
||
| 787 | * WARNING: do not use UTF-8 Option ($convertToUtf8) for binary-files (e.g.: images) !!! |
||
| 788 | * |
||
| 789 | * @link http://php.net/manual/en/function.file-get-contents.php |
||
| 790 | * |
||
| 791 | * @param string $filename <p> |
||
| 792 | * Name of the file to read. |
||
| 793 | * </p> |
||
| 794 | * @param bool $use_include_path [optional] <p> |
||
| 795 | * Prior to PHP 5, this parameter is called |
||
| 796 | * use_include_path and is a bool. |
||
| 797 | * As of PHP 5 the FILE_USE_INCLUDE_PATH can be used |
||
| 798 | * to trigger include path |
||
| 799 | * search. |
||
| 800 | * </p> |
||
| 801 | * @param resource|null $context [optional] <p> |
||
| 802 | * A valid context resource created with |
||
| 803 | * stream_context_create. If you don't need to use a |
||
| 804 | * custom context, you can skip this parameter by &null;. |
||
| 805 | * </p> |
||
| 806 | * @param int|null $offset [optional] <p> |
||
| 807 | * The offset where the reading starts. |
||
| 808 | * </p> |
||
| 809 | * @param int|null $maxLength [optional] <p> |
||
| 810 | * Maximum length of data read. The default is to read until end |
||
| 811 | * of file is reached. |
||
| 812 | * </p> |
||
| 813 | * @param int $timeout <p>The time in seconds for the timeout.</p> |
||
| 814 | * |
||
| 815 | * @param bool $convertToUtf8 <strong>WARNING!!!</strong> <p>Maybe you can't use this option for e.g. |
||
| 816 | * images or pdf, because they used non default utf-8 chars</p> |
||
| 817 | * |
||
| 818 | * @return string|false <p>The function returns the read data or false on failure.</p> |
||
| 819 | */ |
||
| 820 | 4 | 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) |
|
| 821 | { |
||
| 822 | // init |
||
| 823 | 4 | $filename = \filter_var($filename, FILTER_SANITIZE_STRING); |
|
| 824 | |||
| 825 | 4 | if ($timeout && $context === null) { |
|
| 826 | 3 | $context = \stream_context_create( |
|
| 827 | [ |
||
| 828 | 'http' => |
||
| 829 | [ |
||
| 830 | 3 | 'timeout' => $timeout, |
|
| 831 | ], |
||
| 832 | ] |
||
| 833 | ); |
||
| 834 | } |
||
| 835 | |||
| 836 | 4 | if ($offset === null) { |
|
| 837 | 4 | $offset = 0; |
|
| 838 | } |
||
| 839 | |||
| 840 | 4 | if (\is_int($maxLength) === true) { |
|
| 841 | 1 | $data = \file_get_contents($filename, $use_include_path, $context, $offset, $maxLength); |
|
| 842 | } else { |
||
| 843 | 4 | $data = \file_get_contents($filename, $use_include_path, $context, $offset); |
|
| 844 | } |
||
| 845 | |||
| 846 | // return false on error |
||
| 847 | 4 | if ($data === false) { |
|
| 848 | return false; |
||
| 849 | } |
||
| 850 | |||
| 851 | 4 | if ($convertToUtf8 === true) { |
|
| 852 | 4 | $data = self::encode('UTF-8', $data, false); |
|
| 853 | 4 | $data = self::cleanup($data); |
|
| 854 | } |
||
| 855 | |||
| 856 | 4 | return $data; |
|
| 857 | } |
||
| 858 | |||
| 859 | /** |
||
| 860 | * Checks if a file starts with BOM (Byte Order Mark) character. |
||
| 861 | * |
||
| 862 | * @param string $file_path <p>Path to a valid file.</p> |
||
| 863 | * |
||
| 864 | * @return bool <p><strong>true</strong> if the file has BOM at the start, <strong>false</strong> otherwise.</> |
||
| 865 | */ |
||
| 866 | 1 | public static function file_has_bom(string $file_path): bool |
|
| 867 | { |
||
| 868 | 1 | return self::string_has_bom(\file_get_contents($file_path)); |
|
| 869 | } |
||
| 870 | |||
| 871 | /** |
||
| 872 | * Normalizes to UTF-8 NFC, converting from WINDOWS-1252 when needed. |
||
| 873 | * |
||
| 874 | * @param mixed $var |
||
| 875 | * @param int $normalization_form |
||
| 876 | * @param string $leading_combining |
||
| 877 | * |
||
| 878 | * @return mixed |
||
| 879 | */ |
||
| 880 | 9 | public static function filter($var, int $normalization_form = 4 /* n::NFC */, string $leading_combining = '◌') |
|
| 934 | |||
| 935 | /** |
||
| 936 | * "filter_input()"-wrapper with normalizes to UTF-8 NFC, converting from WINDOWS-1252 when needed. |
||
| 937 | * |
||
| 938 | * Gets a specific external variable by name and optionally filters it |
||
| 939 | * |
||
| 940 | * @link http://php.net/manual/en/function.filter-input.php |
||
| 941 | * |
||
| 942 | * @param int $type <p> |
||
| 943 | * One of <b>INPUT_GET</b>, <b>INPUT_POST</b>, |
||
| 944 | * <b>INPUT_COOKIE</b>, <b>INPUT_SERVER</b>, or |
||
| 945 | * <b>INPUT_ENV</b>. |
||
| 946 | * </p> |
||
| 947 | * @param string $variable_name <p> |
||
| 948 | * Name of a variable to get. |
||
| 949 | * </p> |
||
| 950 | * @param int $filter [optional] <p> |
||
| 951 | * The ID of the filter to apply. The |
||
| 952 | * manual page lists the available filters. |
||
| 953 | * </p> |
||
| 954 | * @param mixed $options [optional] <p> |
||
| 955 | * Associative array of options or bitwise disjunction of flags. If filter |
||
| 956 | * accepts options, flags can be provided in "flags" field of array. |
||
| 957 | * </p> |
||
| 958 | * |
||
| 959 | * @return mixed Value of the requested variable on success, <b>FALSE</b> if the filter fails, |
||
| 960 | * or <b>NULL</b> if the <i>variable_name</i> variable is not set. |
||
| 961 | * If the flag <b>FILTER_NULL_ON_FAILURE</b> is used, it |
||
| 962 | * returns <b>FALSE</b> if the variable is not set and <b>NULL</b> if the filter fails. |
||
| 963 | * @since 5.2.0 |
||
| 964 | */ |
||
| 965 | View Code Duplication | public static function filter_input(int $type, string $variable_name, int $filter = FILTER_DEFAULT, $options = null) |
|
| 975 | |||
| 976 | /** |
||
| 977 | * "filter_input_array()"-wrapper with normalizes to UTF-8 NFC, converting from WINDOWS-1252 when needed. |
||
| 978 | * |
||
| 979 | * Gets external variables and optionally filters them |
||
| 980 | * |
||
| 981 | * @link http://php.net/manual/en/function.filter-input-array.php |
||
| 982 | * |
||
| 983 | * @param int $type <p> |
||
| 984 | * One of <b>INPUT_GET</b>, <b>INPUT_POST</b>, |
||
| 985 | * <b>INPUT_COOKIE</b>, <b>INPUT_SERVER</b>, or |
||
| 986 | * <b>INPUT_ENV</b>. |
||
| 987 | * </p> |
||
| 988 | * @param mixed $definition [optional] <p> |
||
| 989 | * An array defining the arguments. A valid key is a string |
||
| 990 | * containing a variable name and a valid value is either a filter type, or an array |
||
| 991 | * optionally specifying the filter, flags and options. If the value is an |
||
| 992 | * array, valid keys are filter which specifies the |
||
| 993 | * filter type, |
||
| 994 | * flags which specifies any flags that apply to the |
||
| 995 | * filter, and options which specifies any options that |
||
| 996 | * apply to the filter. See the example below for a better understanding. |
||
| 997 | * </p> |
||
| 998 | * <p> |
||
| 999 | * This parameter can be also an integer holding a filter constant. Then all values in the |
||
| 1000 | * input array are filtered by this filter. |
||
| 1001 | * </p> |
||
| 1002 | * @param bool $add_empty [optional] <p> |
||
| 1003 | * Add missing keys as <b>NULL</b> to the return value. |
||
| 1004 | * </p> |
||
| 1005 | * |
||
| 1006 | * @return mixed An array containing the values of the requested variables on success, or <b>FALSE</b> |
||
| 1007 | * on failure. An array value will be <b>FALSE</b> if the filter fails, or <b>NULL</b> if |
||
| 1008 | * the variable is not set. Or if the flag <b>FILTER_NULL_ON_FAILURE</b> |
||
| 1009 | * is used, it returns <b>FALSE</b> if the variable is not set and <b>NULL</b> if the filter |
||
| 1010 | * fails. |
||
| 1011 | * @since 5.2.0 |
||
| 1012 | */ |
||
| 1013 | View Code Duplication | public static function filter_input_array(int $type, $definition = null, bool $add_empty = true) |
|
| 1023 | |||
| 1024 | /** |
||
| 1025 | * "filter_var()"-wrapper with normalizes to UTF-8 NFC, converting from WINDOWS-1252 when needed. |
||
| 1026 | * |
||
| 1027 | * Filters a variable with a specified filter |
||
| 1028 | * |
||
| 1029 | * @link http://php.net/manual/en/function.filter-var.php |
||
| 1030 | * |
||
| 1031 | * @param mixed $variable <p> |
||
| 1032 | * Value to filter. |
||
| 1033 | * </p> |
||
| 1034 | * @param int $filter [optional] <p> |
||
| 1035 | * The ID of the filter to apply. The |
||
| 1036 | * manual page lists the available filters. |
||
| 1037 | * </p> |
||
| 1038 | * @param mixed $options [optional] <p> |
||
| 1039 | * Associative array of options or bitwise disjunction of flags. If filter |
||
| 1040 | * accepts options, flags can be provided in "flags" field of array. For |
||
| 1041 | * the "callback" filter, callable type should be passed. The |
||
| 1042 | * callback must accept one argument, the value to be filtered, and return |
||
| 1043 | * the value after filtering/sanitizing it. |
||
| 1044 | * </p> |
||
| 1045 | * <p> |
||
| 1046 | * <code> |
||
| 1047 | * // for filters that accept options, use this format |
||
| 1048 | * $options = array( |
||
| 1049 | * 'options' => array( |
||
| 1050 | * 'default' => 3, // value to return if the filter fails |
||
| 1051 | * // other options here |
||
| 1052 | * 'min_range' => 0 |
||
| 1053 | * ), |
||
| 1054 | * 'flags' => FILTER_FLAG_ALLOW_OCTAL, |
||
| 1055 | * ); |
||
| 1056 | * $var = filter_var('0755', FILTER_VALIDATE_INT, $options); |
||
| 1057 | * // for filter that only accept flags, you can pass them directly |
||
| 1058 | * $var = filter_var('oops', FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE); |
||
| 1059 | * // for filter that only accept flags, you can also pass as an array |
||
| 1060 | * $var = filter_var('oops', FILTER_VALIDATE_BOOLEAN, |
||
| 1061 | * array('flags' => FILTER_NULL_ON_FAILURE)); |
||
| 1062 | * // callback validate filter |
||
| 1063 | * function foo($value) |
||
| 1064 | * { |
||
| 1065 | * // Expected format: Surname, GivenNames |
||
| 1066 | * if (strpos($value, ", ") === false) return false; |
||
| 1067 | * list($surname, $givennames) = explode(", ", $value, 2); |
||
| 1068 | * $empty = (empty($surname) || empty($givennames)); |
||
| 1069 | * $notstrings = (!is_string($surname) || !is_string($givennames)); |
||
| 1070 | * if ($empty || $notstrings) { |
||
| 1071 | * return false; |
||
| 1072 | * } else { |
||
| 1073 | * return $value; |
||
| 1074 | * } |
||
| 1075 | * } |
||
| 1076 | * $var = filter_var('Doe, Jane Sue', FILTER_CALLBACK, array('options' => 'foo')); |
||
| 1077 | * </code> |
||
| 1078 | * </p> |
||
| 1079 | * |
||
| 1080 | * @return mixed the filtered data, or <b>FALSE</b> if the filter fails. |
||
| 1081 | * @since 5.2.0 |
||
| 1082 | */ |
||
| 1083 | 1 | View Code Duplication | public static function filter_var($variable, int $filter = FILTER_DEFAULT, $options = null) |
| 1093 | |||
| 1094 | /** |
||
| 1095 | * "filter_var_array()"-wrapper with normalizes to UTF-8 NFC, converting from WINDOWS-1252 when needed. |
||
| 1096 | * |
||
| 1097 | * Gets multiple variables and optionally filters them |
||
| 1098 | * |
||
| 1099 | * @link http://php.net/manual/en/function.filter-var-array.php |
||
| 1100 | * |
||
| 1101 | * @param array $data <p> |
||
| 1102 | * An array with string keys containing the data to filter. |
||
| 1103 | * </p> |
||
| 1104 | * @param mixed $definition [optional] <p> |
||
| 1105 | * An array defining the arguments. A valid key is a string |
||
| 1106 | * containing a variable name and a valid value is either a |
||
| 1107 | * filter type, or an |
||
| 1108 | * array optionally specifying the filter, flags and options. |
||
| 1109 | * If the value is an array, valid keys are filter |
||
| 1110 | * which specifies the filter type, |
||
| 1111 | * flags which specifies any flags that apply to the |
||
| 1112 | * filter, and options which specifies any options that |
||
| 1113 | * apply to the filter. See the example below for a better understanding. |
||
| 1114 | * </p> |
||
| 1115 | * <p> |
||
| 1116 | * This parameter can be also an integer holding a filter constant. Then all values in the |
||
| 1117 | * input array are filtered by this filter. |
||
| 1118 | * </p> |
||
| 1119 | * @param bool $add_empty [optional] <p> |
||
| 1120 | * Add missing keys as <b>NULL</b> to the return value. |
||
| 1121 | * </p> |
||
| 1122 | * |
||
| 1123 | * @return mixed An array containing the values of the requested variables on success, or <b>FALSE</b> |
||
| 1124 | * on failure. An array value will be <b>FALSE</b> if the filter fails, or <b>NULL</b> if |
||
| 1125 | * the variable is not set. |
||
| 1126 | * @since 5.2.0 |
||
| 1127 | */ |
||
| 1128 | 1 | View Code Duplication | public static function filter_var_array(array $data, $definition = null, bool $add_empty = true) |
| 1138 | |||
| 1139 | /** |
||
| 1140 | * Check if the number of unicode characters are not more than the specified integer. |
||
| 1141 | * |
||
| 1142 | * @param string $str The original string to be checked. |
||
| 1143 | * @param int $box_size The size in number of chars to be checked against string. |
||
| 1144 | * |
||
| 1145 | * @return bool true if string is less than or equal to $box_size, false otherwise. |
||
| 1146 | */ |
||
| 1147 | 1 | public static function fits_inside(string $str, int $box_size): bool |
|
| 1151 | |||
| 1152 | /** |
||
| 1153 | * Try to fix simple broken UTF-8 strings. |
||
| 1154 | * |
||
| 1155 | * INFO: Take a look at "UTF8::fix_utf8()" if you need a more advanced fix for broken UTF-8 strings. |
||
| 1156 | * |
||
| 1157 | * If you received an UTF-8 string that was converted from Windows-1252 as it was ISO-8859-1 |
||
| 1158 | * (ignoring Windows-1252 chars from 80 to 9F) use this function to fix it. |
||
| 1159 | * See: http://en.wikipedia.org/wiki/Windows-1252 |
||
| 1160 | * |
||
| 1161 | * @param string $str <p>The input string</p> |
||
| 1162 | * |
||
| 1163 | * @return string |
||
| 1164 | */ |
||
| 1165 | 28 | View Code Duplication | public static function fix_simple_utf8(string $str): string |
| 1186 | |||
| 1187 | /** |
||
| 1188 | * Fix a double (or multiple) encoded UTF8 string. |
||
| 1189 | * |
||
| 1190 | * @param string|string[] $str <p>You can use a string or an array of strings.</p> |
||
| 1191 | * |
||
| 1192 | * @return string|string[] <p>Will return the fixed input-"array" or |
||
| 1193 | * the fixed input-"string".</p> |
||
| 1194 | */ |
||
| 1195 | 1 | public static function fix_utf8($str) |
|
| 1215 | |||
| 1216 | /** |
||
| 1217 | * Get character of a specific character. |
||
| 1218 | * |
||
| 1219 | * @param string $char |
||
| 1220 | * |
||
| 1221 | * @return string <p>'RTL' or 'LTR'</p> |
||
| 1222 | */ |
||
| 1223 | 1 | public static function getCharDirection(string $char): string |
|
| 1337 | |||
| 1338 | /** |
||
| 1339 | * get data from "/data/*.ser" |
||
| 1340 | * |
||
| 1341 | * @param string $file |
||
| 1342 | * |
||
| 1343 | * @return bool|string|array|int <p>Will return false on error.</p> |
||
| 1344 | */ |
||
| 1345 | 6 | private static function getData(string $file) |
|
| 1355 | |||
| 1356 | /** |
||
| 1357 | * Check for php-support. |
||
| 1358 | * |
||
| 1359 | * @param string|null $key |
||
| 1360 | * |
||
| 1361 | * @return mixed <p>Return the full support-"array", if $key === null<br> |
||
| 1362 | * return bool-value, if $key is used and available<br> |
||
| 1363 | * otherwise return null</p> |
||
| 1364 | */ |
||
| 1365 | 19 | public static function getSupportInfo(string $key = null) |
|
| 1381 | |||
| 1382 | /** |
||
| 1383 | * alias for "UTF8::string_has_bom()" |
||
| 1384 | * |
||
| 1385 | * @see UTF8::string_has_bom() |
||
| 1386 | * |
||
| 1387 | * @param string $str |
||
| 1388 | * |
||
| 1389 | * @return bool |
||
| 1390 | * |
||
| 1391 | * @deprecated <p>use "UTF8::string_has_bom()"</p> |
||
| 1392 | */ |
||
| 1393 | 1 | public static function hasBom(string $str): bool |
|
| 1397 | |||
| 1398 | /** |
||
| 1399 | * Converts a hexadecimal-value into an UTF-8 character. |
||
| 1400 | * |
||
| 1401 | * @param string $hexdec <p>The hexadecimal value.</p> |
||
| 1402 | * |
||
| 1403 | * @return string|false <p>One single UTF-8 character.</p> |
||
| 1404 | */ |
||
| 1405 | 2 | public static function hex_to_chr(string $hexdec) |
|
| 1409 | |||
| 1410 | /** |
||
| 1411 | * Converts hexadecimal U+xxxx code point representation to integer. |
||
| 1412 | * |
||
| 1413 | * INFO: opposite to UTF8::int_to_hex() |
||
| 1414 | * |
||
| 1415 | * @param string $hexDec <p>The hexadecimal code point representation.</p> |
||
| 1416 | * |
||
| 1417 | * @return int|false <p>The code point, or false on failure.</p> |
||
| 1418 | */ |
||
| 1419 | 1 | public static function hex_to_int(string $hexDec) |
|
| 1431 | |||
| 1432 | /** |
||
| 1433 | * alias for "UTF8::html_entity_decode()" |
||
| 1434 | * |
||
| 1435 | * @see UTF8::html_entity_decode() |
||
| 1436 | * |
||
| 1437 | * @param string $str |
||
| 1438 | * @param int $flags |
||
| 1439 | * @param string $encoding |
||
| 1440 | * |
||
| 1441 | * @return string |
||
| 1442 | */ |
||
| 1443 | 1 | public static function html_decode(string $str, int $flags = null, string $encoding = 'UTF-8'): string |
|
| 1447 | |||
| 1448 | /** |
||
| 1449 | * Converts a UTF-8 string to a series of HTML numbered entities. |
||
| 1450 | * |
||
| 1451 | * INFO: opposite to UTF8::html_decode() |
||
| 1452 | * |
||
| 1453 | * @param string $str <p>The Unicode string to be encoded as numbered entities.</p> |
||
| 1454 | * @param bool $keepAsciiChars [optional] <p>Keep ASCII chars.</p> |
||
| 1455 | * @param string $encoding [optional] <p>Default is UTF-8</p> |
||
| 1456 | * |
||
| 1457 | * @return string <p>HTML numbered entities.</p> |
||
| 1458 | */ |
||
| 1459 | 2 | public static function html_encode(string $str, bool $keepAsciiChars = false, string $encoding = 'UTF-8'): string |
|
| 1494 | |||
| 1495 | /** |
||
| 1496 | * UTF-8 version of html_entity_decode() |
||
| 1497 | * |
||
| 1498 | * The reason we are not using html_entity_decode() by itself is because |
||
| 1499 | * while it is not technically correct to leave out the semicolon |
||
| 1500 | * at the end of an entity most browsers will still interpret the entity |
||
| 1501 | * correctly. html_entity_decode() does not convert entities without |
||
| 1502 | * semicolons, so we are left with our own little solution here. Bummer. |
||
| 1503 | * |
||
| 1504 | * Convert all HTML entities to their applicable characters |
||
| 1505 | * |
||
| 1506 | * INFO: opposite to UTF8::html_encode() |
||
| 1507 | * |
||
| 1508 | * @link http://php.net/manual/en/function.html-entity-decode.php |
||
| 1509 | * |
||
| 1510 | * @param string $str <p> |
||
| 1511 | * The input string. |
||
| 1512 | * </p> |
||
| 1513 | * @param int $flags [optional] <p> |
||
| 1514 | * A bitmask of one or more of the following flags, which specify how to handle quotes and |
||
| 1515 | * which document type to use. The default is ENT_COMPAT | ENT_HTML401. |
||
| 1516 | * <table> |
||
| 1517 | * Available <i>flags</i> constants |
||
| 1518 | * <tr valign="top"> |
||
| 1519 | * <td>Constant Name</td> |
||
| 1520 | * <td>Description</td> |
||
| 1521 | * </tr> |
||
| 1522 | * <tr valign="top"> |
||
| 1523 | * <td><b>ENT_COMPAT</b></td> |
||
| 1524 | * <td>Will convert double-quotes and leave single-quotes alone.</td> |
||
| 1525 | * </tr> |
||
| 1526 | * <tr valign="top"> |
||
| 1527 | * <td><b>ENT_QUOTES</b></td> |
||
| 1528 | * <td>Will convert both double and single quotes.</td> |
||
| 1529 | * </tr> |
||
| 1530 | * <tr valign="top"> |
||
| 1531 | * <td><b>ENT_NOQUOTES</b></td> |
||
| 1532 | * <td>Will leave both double and single quotes unconverted.</td> |
||
| 1533 | * </tr> |
||
| 1534 | * <tr valign="top"> |
||
| 1535 | * <td><b>ENT_HTML401</b></td> |
||
| 1536 | * <td> |
||
| 1537 | * Handle code as HTML 4.01. |
||
| 1538 | * </td> |
||
| 1539 | * </tr> |
||
| 1540 | * <tr valign="top"> |
||
| 1541 | * <td><b>ENT_XML1</b></td> |
||
| 1542 | * <td> |
||
| 1543 | * Handle code as XML 1. |
||
| 1544 | * </td> |
||
| 1545 | * </tr> |
||
| 1546 | * <tr valign="top"> |
||
| 1547 | * <td><b>ENT_XHTML</b></td> |
||
| 1548 | * <td> |
||
| 1549 | * Handle code as XHTML. |
||
| 1550 | * </td> |
||
| 1551 | * </tr> |
||
| 1552 | * <tr valign="top"> |
||
| 1553 | * <td><b>ENT_HTML5</b></td> |
||
| 1554 | * <td> |
||
| 1555 | * Handle code as HTML 5. |
||
| 1556 | * </td> |
||
| 1557 | * </tr> |
||
| 1558 | * </table> |
||
| 1559 | * </p> |
||
| 1560 | * @param string $encoding [optional] <p>Encoding to use.</p> |
||
| 1561 | * |
||
| 1562 | * @return string <p>The decoded string.</p> |
||
| 1563 | */ |
||
| 1564 | 17 | public static function html_entity_decode(string $str, int $flags = null, string $encoding = 'UTF-8'): string |
|
| 1632 | |||
| 1633 | /** |
||
| 1634 | * Convert all applicable characters to HTML entities: UTF-8 version of htmlentities() |
||
| 1635 | * |
||
| 1636 | * @link http://php.net/manual/en/function.htmlentities.php |
||
| 1637 | * |
||
| 1638 | * @param string $str <p> |
||
| 1639 | * The input string. |
||
| 1640 | * </p> |
||
| 1641 | * @param int $flags [optional] <p> |
||
| 1642 | * A bitmask of one or more of the following flags, which specify how to handle quotes, |
||
| 1643 | * invalid code unit sequences and the used document type. The default is |
||
| 1644 | * ENT_COMPAT | ENT_HTML401. |
||
| 1645 | * <table> |
||
| 1646 | * Available <i>flags</i> constants |
||
| 1647 | * <tr valign="top"> |
||
| 1648 | * <td>Constant Name</td> |
||
| 1649 | * <td>Description</td> |
||
| 1650 | * </tr> |
||
| 1651 | * <tr valign="top"> |
||
| 1652 | * <td><b>ENT_COMPAT</b></td> |
||
| 1653 | * <td>Will convert double-quotes and leave single-quotes alone.</td> |
||
| 1654 | * </tr> |
||
| 1655 | * <tr valign="top"> |
||
| 1656 | * <td><b>ENT_QUOTES</b></td> |
||
| 1657 | * <td>Will convert both double and single quotes.</td> |
||
| 1658 | * </tr> |
||
| 1659 | * <tr valign="top"> |
||
| 1660 | * <td><b>ENT_NOQUOTES</b></td> |
||
| 1661 | * <td>Will leave both double and single quotes unconverted.</td> |
||
| 1662 | * </tr> |
||
| 1663 | * <tr valign="top"> |
||
| 1664 | * <td><b>ENT_IGNORE</b></td> |
||
| 1665 | * <td> |
||
| 1666 | * Silently discard invalid code unit sequences instead of returning |
||
| 1667 | * an empty string. Using this flag is discouraged as it |
||
| 1668 | * may have security implications. |
||
| 1669 | * </td> |
||
| 1670 | * </tr> |
||
| 1671 | * <tr valign="top"> |
||
| 1672 | * <td><b>ENT_SUBSTITUTE</b></td> |
||
| 1673 | * <td> |
||
| 1674 | * Replace invalid code unit sequences with a Unicode Replacement Character |
||
| 1675 | * U+FFFD (UTF-8) or &#38;#FFFD; (otherwise) instead of returning an empty string. |
||
| 1676 | * </td> |
||
| 1677 | * </tr> |
||
| 1678 | * <tr valign="top"> |
||
| 1679 | * <td><b>ENT_DISALLOWED</b></td> |
||
| 1680 | * <td> |
||
| 1681 | * Replace invalid code points for the given document type with a |
||
| 1682 | * Unicode Replacement Character U+FFFD (UTF-8) or &#38;#FFFD; |
||
| 1683 | * (otherwise) instead of leaving them as is. This may be useful, for |
||
| 1684 | * instance, to ensure the well-formedness of XML documents with |
||
| 1685 | * embedded external content. |
||
| 1686 | * </td> |
||
| 1687 | * </tr> |
||
| 1688 | * <tr valign="top"> |
||
| 1689 | * <td><b>ENT_HTML401</b></td> |
||
| 1690 | * <td> |
||
| 1691 | * Handle code as HTML 4.01. |
||
| 1692 | * </td> |
||
| 1693 | * </tr> |
||
| 1694 | * <tr valign="top"> |
||
| 1695 | * <td><b>ENT_XML1</b></td> |
||
| 1696 | * <td> |
||
| 1697 | * Handle code as XML 1. |
||
| 1698 | * </td> |
||
| 1699 | * </tr> |
||
| 1700 | * <tr valign="top"> |
||
| 1701 | * <td><b>ENT_XHTML</b></td> |
||
| 1702 | * <td> |
||
| 1703 | * Handle code as XHTML. |
||
| 1704 | * </td> |
||
| 1705 | * </tr> |
||
| 1706 | * <tr valign="top"> |
||
| 1707 | * <td><b>ENT_HTML5</b></td> |
||
| 1708 | * <td> |
||
| 1709 | * Handle code as HTML 5. |
||
| 1710 | * </td> |
||
| 1711 | * </tr> |
||
| 1712 | * </table> |
||
| 1713 | * </p> |
||
| 1714 | * @param string $encoding [optional] <p> |
||
| 1715 | * Like <b>htmlspecialchars</b>, |
||
| 1716 | * <b>htmlentities</b> takes an optional third argument |
||
| 1717 | * <i>encoding</i> which defines encoding used in |
||
| 1718 | * conversion. |
||
| 1719 | * Although this argument is technically optional, you are highly |
||
| 1720 | * encouraged to specify the correct value for your code. |
||
| 1721 | * </p> |
||
| 1722 | * @param bool $double_encode [optional] <p> |
||
| 1723 | * When <i>double_encode</i> is turned off PHP will not |
||
| 1724 | * encode existing html entities. The default is to convert everything. |
||
| 1725 | * </p> |
||
| 1726 | * |
||
| 1727 | * |
||
| 1728 | * @return string the encoded string. |
||
| 1729 | * </p> |
||
| 1730 | * <p> |
||
| 1731 | * If the input <i>string</i> contains an invalid code unit |
||
| 1732 | * sequence within the given <i>encoding</i> an empty string |
||
| 1733 | * will be returned, unless either the <b>ENT_IGNORE</b> or |
||
| 1734 | * <b>ENT_SUBSTITUTE</b> flags are set. |
||
| 1735 | */ |
||
| 1736 | 2 | public static function htmlentities(string $str, int $flags = ENT_COMPAT, string $encoding = 'UTF-8', bool $double_encode = true): string |
|
| 1774 | |||
| 1775 | /** |
||
| 1776 | * Convert only special characters to HTML entities: UTF-8 version of htmlspecialchars() |
||
| 1777 | * |
||
| 1778 | * INFO: Take a look at "UTF8::htmlentities()" |
||
| 1779 | * |
||
| 1780 | * @link http://php.net/manual/en/function.htmlspecialchars.php |
||
| 1781 | * |
||
| 1782 | * @param string $str <p> |
||
| 1783 | * The string being converted. |
||
| 1784 | * </p> |
||
| 1785 | * @param int $flags [optional] <p> |
||
| 1786 | * A bitmask of one or more of the following flags, which specify how to handle quotes, |
||
| 1787 | * invalid code unit sequences and the used document type. The default is |
||
| 1788 | * ENT_COMPAT | ENT_HTML401. |
||
| 1789 | * <table> |
||
| 1790 | * Available <i>flags</i> constants |
||
| 1791 | * <tr valign="top"> |
||
| 1792 | * <td>Constant Name</td> |
||
| 1793 | * <td>Description</td> |
||
| 1794 | * </tr> |
||
| 1795 | * <tr valign="top"> |
||
| 1796 | * <td><b>ENT_COMPAT</b></td> |
||
| 1797 | * <td>Will convert double-quotes and leave single-quotes alone.</td> |
||
| 1798 | * </tr> |
||
| 1799 | * <tr valign="top"> |
||
| 1800 | * <td><b>ENT_QUOTES</b></td> |
||
| 1801 | * <td>Will convert both double and single quotes.</td> |
||
| 1802 | * </tr> |
||
| 1803 | * <tr valign="top"> |
||
| 1804 | * <td><b>ENT_NOQUOTES</b></td> |
||
| 1805 | * <td>Will leave both double and single quotes unconverted.</td> |
||
| 1806 | * </tr> |
||
| 1807 | * <tr valign="top"> |
||
| 1808 | * <td><b>ENT_IGNORE</b></td> |
||
| 1809 | * <td> |
||
| 1810 | * Silently discard invalid code unit sequences instead of returning |
||
| 1811 | * an empty string. Using this flag is discouraged as it |
||
| 1812 | * may have security implications. |
||
| 1813 | * </td> |
||
| 1814 | * </tr> |
||
| 1815 | * <tr valign="top"> |
||
| 1816 | * <td><b>ENT_SUBSTITUTE</b></td> |
||
| 1817 | * <td> |
||
| 1818 | * Replace invalid code unit sequences with a Unicode Replacement Character |
||
| 1819 | * U+FFFD (UTF-8) or &#38;#FFFD; (otherwise) instead of returning an empty string. |
||
| 1820 | * </td> |
||
| 1821 | * </tr> |
||
| 1822 | * <tr valign="top"> |
||
| 1823 | * <td><b>ENT_DISALLOWED</b></td> |
||
| 1824 | * <td> |
||
| 1825 | * Replace invalid code points for the given document type with a |
||
| 1826 | * Unicode Replacement Character U+FFFD (UTF-8) or &#38;#FFFD; |
||
| 1827 | * (otherwise) instead of leaving them as is. This may be useful, for |
||
| 1828 | * instance, to ensure the well-formedness of XML documents with |
||
| 1829 | * embedded external content. |
||
| 1830 | * </td> |
||
| 1831 | * </tr> |
||
| 1832 | * <tr valign="top"> |
||
| 1833 | * <td><b>ENT_HTML401</b></td> |
||
| 1834 | * <td> |
||
| 1835 | * Handle code as HTML 4.01. |
||
| 1836 | * </td> |
||
| 1837 | * </tr> |
||
| 1838 | * <tr valign="top"> |
||
| 1839 | * <td><b>ENT_XML1</b></td> |
||
| 1840 | * <td> |
||
| 1841 | * Handle code as XML 1. |
||
| 1842 | * </td> |
||
| 1843 | * </tr> |
||
| 1844 | * <tr valign="top"> |
||
| 1845 | * <td><b>ENT_XHTML</b></td> |
||
| 1846 | * <td> |
||
| 1847 | * Handle code as XHTML. |
||
| 1848 | * </td> |
||
| 1849 | * </tr> |
||
| 1850 | * <tr valign="top"> |
||
| 1851 | * <td><b>ENT_HTML5</b></td> |
||
| 1852 | * <td> |
||
| 1853 | * Handle code as HTML 5. |
||
| 1854 | * </td> |
||
| 1855 | * </tr> |
||
| 1856 | * </table> |
||
| 1857 | * </p> |
||
| 1858 | * @param string $encoding [optional] <p> |
||
| 1859 | * Defines encoding used in conversion. |
||
| 1860 | * </p> |
||
| 1861 | * <p> |
||
| 1862 | * For the purposes of this function, the encodings |
||
| 1863 | * ISO-8859-1, ISO-8859-15, |
||
| 1864 | * UTF-8, cp866, |
||
| 1865 | * cp1251, cp1252, and |
||
| 1866 | * KOI8-R are effectively equivalent, provided the |
||
| 1867 | * <i>string</i> itself is valid for the encoding, as |
||
| 1868 | * the characters affected by <b>htmlspecialchars</b> occupy |
||
| 1869 | * the same positions in all of these encodings. |
||
| 1870 | * </p> |
||
| 1871 | * @param bool $double_encode [optional] <p> |
||
| 1872 | * When <i>double_encode</i> is turned off PHP will not |
||
| 1873 | * encode existing html entities, the default is to convert everything. |
||
| 1874 | * </p> |
||
| 1875 | * |
||
| 1876 | * @return string The converted string. |
||
| 1877 | * </p> |
||
| 1878 | * <p> |
||
| 1879 | * If the input <i>string</i> contains an invalid code unit |
||
| 1880 | * sequence within the given <i>encoding</i> an empty string |
||
| 1881 | * will be returned, unless either the <b>ENT_IGNORE</b> or |
||
| 1882 | * <b>ENT_SUBSTITUTE</b> flags are set. |
||
| 1883 | */ |
||
| 1884 | 1 | public static function htmlspecialchars(string $str, int $flags = ENT_COMPAT, string $encoding = 'UTF-8', bool $double_encode = true): string |
|
| 1892 | |||
| 1893 | /** |
||
| 1894 | * Checks whether iconv is available on the server. |
||
| 1895 | * |
||
| 1896 | * @return bool <p><strong>true</strong> if available, <strong>false</strong> otherwise.</p> |
||
| 1897 | */ |
||
| 1898 | 1 | public static function iconv_loaded(): bool |
|
| 1902 | |||
| 1903 | /** |
||
| 1904 | * alias for "UTF8::decimal_to_chr()" |
||
| 1905 | * |
||
| 1906 | * @see UTF8::decimal_to_chr() |
||
| 1907 | * |
||
| 1908 | * @param mixed $int |
||
| 1909 | * |
||
| 1910 | * @return string |
||
| 1911 | */ |
||
| 1912 | 2 | public static function int_to_chr($int): string |
|
| 1916 | |||
| 1917 | /** |
||
| 1918 | * Converts Integer to hexadecimal U+xxxx code point representation. |
||
| 1919 | * |
||
| 1920 | * INFO: opposite to UTF8::hex_to_int() |
||
| 1921 | * |
||
| 1922 | * @param int $int <p>The integer to be converted to hexadecimal code point.</p> |
||
| 1923 | * @param string $pfix [optional] |
||
| 1924 | * |
||
| 1925 | * @return string <p>The code point, or empty string on failure.</p> |
||
| 1926 | */ |
||
| 1927 | 3 | public static function int_to_hex(int $int, string $pfix = 'U+'): string |
|
| 1935 | |||
| 1936 | /** |
||
| 1937 | * Checks whether intl-char is available on the server. |
||
| 1938 | * |
||
| 1939 | * @return bool <p><strong>true</strong> if available, <strong>false</strong> otherwise.</p> |
||
| 1940 | */ |
||
| 1941 | 1 | public static function intlChar_loaded(): bool |
|
| 1945 | |||
| 1946 | /** |
||
| 1947 | * Checks whether intl is available on the server. |
||
| 1948 | * |
||
| 1949 | * @return bool <p><strong>true</strong> if available, <strong>false</strong> otherwise.</p> |
||
| 1950 | */ |
||
| 1951 | 4 | public static function intl_loaded(): bool |
|
| 1955 | |||
| 1956 | /** |
||
| 1957 | * alias for "UTF8::is_ascii()" |
||
| 1958 | * |
||
| 1959 | * @see UTF8::is_ascii() |
||
| 1960 | * |
||
| 1961 | * @param string $str |
||
| 1962 | * |
||
| 1963 | * @return boolean |
||
| 1964 | * |
||
| 1965 | * @deprecated <p>use "UTF8::is_ascii()"</p> |
||
| 1966 | */ |
||
| 1967 | 1 | public static function isAscii(string $str): bool |
|
| 1971 | |||
| 1972 | /** |
||
| 1973 | * alias for "UTF8::is_base64()" |
||
| 1974 | * |
||
| 1975 | * @see UTF8::is_base64() |
||
| 1976 | * |
||
| 1977 | * @param string $str |
||
| 1978 | * |
||
| 1979 | * @return bool |
||
| 1980 | * |
||
| 1981 | * @deprecated <p>use "UTF8::is_base64()"</p> |
||
| 1982 | */ |
||
| 1983 | 1 | public static function isBase64(string $str): bool |
|
| 1987 | |||
| 1988 | /** |
||
| 1989 | * alias for "UTF8::is_binary()" |
||
| 1990 | * |
||
| 1991 | * @see UTF8::is_binary() |
||
| 1992 | * |
||
| 1993 | * @param mixed $str |
||
| 1994 | * |
||
| 1995 | * @return bool |
||
| 1996 | * |
||
| 1997 | * @deprecated <p>use "UTF8::is_binary()"</p> |
||
| 1998 | */ |
||
| 1999 | 1 | public static function isBinary($str): bool |
|
| 2003 | |||
| 2004 | /** |
||
| 2005 | * alias for "UTF8::is_bom()" |
||
| 2006 | * |
||
| 2007 | * @see UTF8::is_bom() |
||
| 2008 | * |
||
| 2009 | * @param string $utf8_chr |
||
| 2010 | * |
||
| 2011 | * @return boolean |
||
| 2012 | * |
||
| 2013 | * @deprecated <p>use "UTF8::is_bom()"</p> |
||
| 2014 | */ |
||
| 2015 | 1 | public static function isBom(string $utf8_chr): bool |
|
| 2019 | |||
| 2020 | /** |
||
| 2021 | * alias for "UTF8::is_html()" |
||
| 2022 | * |
||
| 2023 | * @see UTF8::is_html() |
||
| 2024 | * |
||
| 2025 | * @param string $str |
||
| 2026 | * |
||
| 2027 | * @return boolean |
||
| 2028 | * |
||
| 2029 | * @deprecated <p>use "UTF8::is_html()"</p> |
||
| 2030 | */ |
||
| 2031 | 1 | public static function isHtml(string $str): bool |
|
| 2035 | |||
| 2036 | /** |
||
| 2037 | * alias for "UTF8::is_json()" |
||
| 2038 | * |
||
| 2039 | * @see UTF8::is_json() |
||
| 2040 | * |
||
| 2041 | * @param string $str |
||
| 2042 | * |
||
| 2043 | * @return bool |
||
| 2044 | * |
||
| 2045 | * @deprecated <p>use "UTF8::is_json()"</p> |
||
| 2046 | */ |
||
| 2047 | public static function isJson(string $str): bool |
||
| 2051 | |||
| 2052 | /** |
||
| 2053 | * alias for "UTF8::is_utf16()" |
||
| 2054 | * |
||
| 2055 | * @see UTF8::is_utf16() |
||
| 2056 | * |
||
| 2057 | * @param string $str |
||
| 2058 | * |
||
| 2059 | * @return int|false false if is't not UTF16, 1 for UTF-16LE, 2 for UTF-16BE. |
||
| 2060 | * |
||
| 2061 | * @deprecated <p>use "UTF8::is_utf16()"</p> |
||
| 2062 | */ |
||
| 2063 | 1 | public static function isUtf16(string $str) |
|
| 2067 | |||
| 2068 | /** |
||
| 2069 | * alias for "UTF8::is_utf32()" |
||
| 2070 | * |
||
| 2071 | * @see UTF8::is_utf32() |
||
| 2072 | * |
||
| 2073 | * @param string $str |
||
| 2074 | * |
||
| 2075 | * @return int|false false if is't not UTF16, 1 for UTF-32LE, 2 for UTF-32BE. |
||
| 2076 | * |
||
| 2077 | * @deprecated <p>use "UTF8::is_utf32()"</p> |
||
| 2078 | */ |
||
| 2079 | 1 | public static function isUtf32(string $str) |
|
| 2083 | |||
| 2084 | /** |
||
| 2085 | * alias for "UTF8::is_utf8()" |
||
| 2086 | * |
||
| 2087 | * @see UTF8::is_utf8() |
||
| 2088 | * |
||
| 2089 | * @param string $str |
||
| 2090 | * @param bool $strict |
||
| 2091 | * |
||
| 2092 | * @return bool |
||
| 2093 | * |
||
| 2094 | * @deprecated <p>use "UTF8::is_utf8()"</p> |
||
| 2095 | */ |
||
| 2096 | 16 | public static function isUtf8($str, $strict = false): bool |
|
| 2100 | |||
| 2101 | /** |
||
| 2102 | * Checks if a string is 7 bit ASCII. |
||
| 2103 | * |
||
| 2104 | * @param string $str <p>The string to check.</p> |
||
| 2105 | * |
||
| 2106 | * @return bool <p> |
||
| 2107 | * <strong>true</strong> if it is ASCII<br> |
||
| 2108 | * <strong>false</strong> otherwise |
||
| 2109 | * </p> |
||
| 2110 | */ |
||
| 2111 | 56 | public static function is_ascii(string $str): bool |
|
| 2119 | |||
| 2120 | /** |
||
| 2121 | * Returns true if the string is base64 encoded, false otherwise. |
||
| 2122 | * |
||
| 2123 | * @param string $str <p>The input string.</p> |
||
| 2124 | * |
||
| 2125 | * @return bool <p>Whether or not $str is base64 encoded.</p> |
||
| 2126 | */ |
||
| 2127 | 1 | public static function is_base64(string $str): bool |
|
| 2133 | |||
| 2134 | /** |
||
| 2135 | * Check if the input is binary... (is look like a hack). |
||
| 2136 | * |
||
| 2137 | * @param mixed $input |
||
| 2138 | * |
||
| 2139 | * @return bool |
||
| 2140 | */ |
||
| 2141 | 18 | public static function is_binary($input): bool |
|
| 2163 | |||
| 2164 | /** |
||
| 2165 | * Check if the file is binary. |
||
| 2166 | * |
||
| 2167 | * @param string $file |
||
| 2168 | * |
||
| 2169 | * @return boolean |
||
| 2170 | */ |
||
| 2171 | 1 | public static function is_binary_file($file): bool |
|
| 2183 | |||
| 2184 | /** |
||
| 2185 | * Checks if the given string is equal to any "Byte Order Mark". |
||
| 2186 | * |
||
| 2187 | * WARNING: Use "UTF8::string_has_bom()" if you will check BOM in a string. |
||
| 2188 | * |
||
| 2189 | * @param string $str <p>The input string.</p> |
||
| 2190 | * |
||
| 2191 | * @return bool <p><strong>true</strong> if the $utf8_chr is Byte Order Mark, <strong>false</strong> otherwise.</p> |
||
| 2192 | */ |
||
| 2193 | 1 | public static function is_bom($str): bool |
|
| 2203 | |||
| 2204 | /** |
||
| 2205 | * Check if the string contains any html-tags <lall>. |
||
| 2206 | * |
||
| 2207 | * @param string $str <p>The input string.</p> |
||
| 2208 | * |
||
| 2209 | * @return boolean |
||
| 2210 | */ |
||
| 2211 | 1 | public static function is_html(string $str): bool |
|
| 2224 | |||
| 2225 | /** |
||
| 2226 | * Try to check if "$str" is an json-string. |
||
| 2227 | * |
||
| 2228 | * @param string $str <p>The input string.</p> |
||
| 2229 | * |
||
| 2230 | * @return bool |
||
| 2231 | */ |
||
| 2232 | 1 | public static function is_json(string $str): bool |
|
| 2248 | |||
| 2249 | /** |
||
| 2250 | * Check if the string is UTF-16. |
||
| 2251 | * |
||
| 2252 | * @param string $str <p>The input string.</p> |
||
| 2253 | * |
||
| 2254 | * @return int|false <p> |
||
| 2255 | * <strong>false</strong> if is't not UTF-16,<br> |
||
| 2256 | * <strong>1</strong> for UTF-16LE,<br> |
||
| 2257 | * <strong>2</strong> for UTF-16BE. |
||
| 2258 | * </p> |
||
| 2259 | */ |
||
| 2260 | 6 | View Code Duplication | public static function is_utf16(string $str) |
| 2308 | |||
| 2309 | /** |
||
| 2310 | * Check if the string is UTF-32. |
||
| 2311 | * |
||
| 2312 | * @param string $str |
||
| 2313 | * |
||
| 2314 | * @return int|false <p> |
||
| 2315 | * <strong>false</strong> if is't not UTF-32,<br> |
||
| 2316 | * <strong>1</strong> for UTF-32LE,<br> |
||
| 2317 | * <strong>2</strong> for UTF-32BE. |
||
| 2318 | * </p> |
||
| 2319 | */ |
||
| 2320 | 3 | View Code Duplication | public static function is_utf32(string $str) |
| 2368 | |||
| 2369 | /** |
||
| 2370 | * Checks whether the passed string contains only byte sequences that appear valid UTF-8 characters. |
||
| 2371 | * |
||
| 2372 | * @see http://hsivonen.iki.fi/php-utf8/ |
||
| 2373 | * |
||
| 2374 | * @param string|string[] $str <p>The string to be checked.</p> |
||
| 2375 | * @param bool $strict <p>Check also if the string is not UTF-16 or UTF-32.</p> |
||
| 2376 | * |
||
| 2377 | * @return bool |
||
| 2378 | */ |
||
| 2379 | 61 | public static function is_utf8($str, bool $strict = false): bool |
|
| 2527 | |||
| 2528 | /** |
||
| 2529 | * (PHP 5 >= 5.2.0, PECL json >= 1.2.0)<br/> |
||
| 2530 | * Decodes a JSON string |
||
| 2531 | * |
||
| 2532 | * @link http://php.net/manual/en/function.json-decode.php |
||
| 2533 | * |
||
| 2534 | * @param string $json <p> |
||
| 2535 | * The <i>json</i> string being decoded. |
||
| 2536 | * </p> |
||
| 2537 | * <p> |
||
| 2538 | * This function only works with UTF-8 encoded strings. |
||
| 2539 | * </p> |
||
| 2540 | * <p>PHP implements a superset of |
||
| 2541 | * JSON - it will also encode and decode scalar types and <b>NULL</b>. The JSON standard |
||
| 2542 | * only supports these values when they are nested inside an array or an object. |
||
| 2543 | * </p> |
||
| 2544 | * @param bool $assoc [optional] <p> |
||
| 2545 | * When <b>TRUE</b>, returned objects will be converted into |
||
| 2546 | * associative arrays. |
||
| 2547 | * </p> |
||
| 2548 | * @param int $depth [optional] <p> |
||
| 2549 | * User specified recursion depth. |
||
| 2550 | * </p> |
||
| 2551 | * @param int $options [optional] <p> |
||
| 2552 | * Bitmask of JSON decode options. Currently only |
||
| 2553 | * <b>JSON_BIGINT_AS_STRING</b> |
||
| 2554 | * is supported (default is to cast large integers as floats) |
||
| 2555 | * </p> |
||
| 2556 | * |
||
| 2557 | * @return mixed the value encoded in <i>json</i> in appropriate |
||
| 2558 | * PHP type. Values true, false and |
||
| 2559 | * null (case-insensitive) are returned as <b>TRUE</b>, <b>FALSE</b> |
||
| 2560 | * and <b>NULL</b> respectively. <b>NULL</b> is returned if the |
||
| 2561 | * <i>json</i> cannot be decoded or if the encoded |
||
| 2562 | * data is deeper than the recursion limit. |
||
| 2563 | */ |
||
| 2564 | 2 | public static function json_decode(string $json, bool $assoc = false, int $depth = 512, int $options = 0) |
|
| 2572 | |||
| 2573 | /** |
||
| 2574 | * (PHP 5 >= 5.2.0, PECL json >= 1.2.0)<br/> |
||
| 2575 | * Returns the JSON representation of a value. |
||
| 2576 | * |
||
| 2577 | * @link http://php.net/manual/en/function.json-encode.php |
||
| 2578 | * |
||
| 2579 | * @param mixed $value <p> |
||
| 2580 | * The <i>value</i> being encoded. Can be any type except |
||
| 2581 | * a resource. |
||
| 2582 | * </p> |
||
| 2583 | * <p> |
||
| 2584 | * All string data must be UTF-8 encoded. |
||
| 2585 | * </p> |
||
| 2586 | * <p>PHP implements a superset of |
||
| 2587 | * JSON - it will also encode and decode scalar types and <b>NULL</b>. The JSON standard |
||
| 2588 | * only supports these values when they are nested inside an array or an object. |
||
| 2589 | * </p> |
||
| 2590 | * @param int $options [optional] <p> |
||
| 2591 | * Bitmask consisting of <b>JSON_HEX_QUOT</b>, |
||
| 2592 | * <b>JSON_HEX_TAG</b>, |
||
| 2593 | * <b>JSON_HEX_AMP</b>, |
||
| 2594 | * <b>JSON_HEX_APOS</b>, |
||
| 2595 | * <b>JSON_NUMERIC_CHECK</b>, |
||
| 2596 | * <b>JSON_PRETTY_PRINT</b>, |
||
| 2597 | * <b>JSON_UNESCAPED_SLASHES</b>, |
||
| 2598 | * <b>JSON_FORCE_OBJECT</b>, |
||
| 2599 | * <b>JSON_UNESCAPED_UNICODE</b>. The behaviour of these |
||
| 2600 | * constants is described on |
||
| 2601 | * the JSON constants page. |
||
| 2602 | * </p> |
||
| 2603 | * @param int $depth [optional] <p> |
||
| 2604 | * Set the maximum depth. Must be greater than zero. |
||
| 2605 | * </p> |
||
| 2606 | * |
||
| 2607 | * @return string a JSON encoded string on success or <b>FALSE</b> on failure. |
||
| 2608 | */ |
||
| 2609 | 2 | public static function json_encode($value, int $options = 0, int $depth = 512): string |
|
| 2617 | |||
| 2618 | /** |
||
| 2619 | * Makes string's first char lowercase. |
||
| 2620 | * |
||
| 2621 | * @param string $str <p>The input string</p> |
||
| 2622 | * @param string $encoding [optional] <p>Set the charset.</p> |
||
| 2623 | * @param bool $cleanUtf8 [optional] <p>Remove non UTF-8 chars from the string.</p> |
||
| 2624 | * |
||
| 2625 | * @return string <p>The resulting string</p> |
||
| 2626 | */ |
||
| 2627 | 7 | public static function lcfirst(string $str, string $encoding = 'UTF-8', bool $cleanUtf8 = false): string |
|
| 2642 | |||
| 2643 | /** |
||
| 2644 | * alias for "UTF8::lcfirst()" |
||
| 2645 | * |
||
| 2646 | * @see UTF8::lcfirst() |
||
| 2647 | * |
||
| 2648 | * @param string $word |
||
| 2649 | * @param string $encoding |
||
| 2650 | * @param bool $cleanUtf8 |
||
| 2651 | * |
||
| 2652 | * @return string |
||
| 2653 | */ |
||
| 2654 | 1 | public static function lcword(string $word, string $encoding = 'UTF-8', bool $cleanUtf8 = false): string |
|
| 2658 | |||
| 2659 | /** |
||
| 2660 | * Lowercase for all words in the string. |
||
| 2661 | * |
||
| 2662 | * @param string $str <p>The input string.</p> |
||
| 2663 | * @param string[] $exceptions [optional] <p>Exclusion for some words.</p> |
||
| 2664 | * @param string $charlist [optional] <p>Additional chars that contains to words and do not start a new word.</p> |
||
| 2665 | * @param string $encoding [optional] <p>Set the charset.</p> |
||
| 2666 | * @param bool $cleanUtf8 [optional] <p>Remove non UTF-8 chars from the string.</p> |
||
| 2667 | * |
||
| 2668 | * @return string |
||
| 2669 | */ |
||
| 2670 | 1 | public static function lcwords(string $str, array $exceptions = [], string $charlist = '', string $encoding = 'UTF-8', bool $cleanUtf8 = false): string |
|
| 2708 | |||
| 2709 | /** |
||
| 2710 | * Strip whitespace or other characters from beginning of a UTF-8 string. |
||
| 2711 | * |
||
| 2712 | * @param string $str <p>The string to be trimmed</p> |
||
| 2713 | * @param mixed $chars <p>Optional characters to be stripped</p> |
||
| 2714 | * |
||
| 2715 | * @return string <p>The string with unwanted characters stripped from the left.</p> |
||
| 2716 | */ |
||
| 2717 | 24 | View Code Duplication | public static function ltrim(string $str = '', $chars = INF): string |
| 2730 | |||
| 2731 | /** |
||
| 2732 | * Returns the UTF-8 character with the maximum code point in the given data. |
||
| 2733 | * |
||
| 2734 | * @param mixed $arg <p>A UTF-8 encoded string or an array of such strings.</p> |
||
| 2735 | * |
||
| 2736 | * @return string <p>The character with the highest code point than others.</p> |
||
| 2737 | */ |
||
| 2738 | 1 | View Code Duplication | public static function max($arg): string |
| 2746 | |||
| 2747 | /** |
||
| 2748 | * Calculates and returns the maximum number of bytes taken by any |
||
| 2749 | * UTF-8 encoded character in the given string. |
||
| 2750 | * |
||
| 2751 | * @param string $str <p>The original Unicode string.</p> |
||
| 2752 | * |
||
| 2753 | * @return int <p>Max byte lengths of the given chars.</p> |
||
| 2754 | */ |
||
| 2755 | 1 | public static function max_chr_width(string $str): int |
|
| 2764 | |||
| 2765 | /** |
||
| 2766 | * Checks whether mbstring is available on the server. |
||
| 2767 | * |
||
| 2768 | * @return bool <p><strong>true</strong> if available, <strong>false</strong> otherwise.</p> |
||
| 2769 | */ |
||
| 2770 | 12 | public static function mbstring_loaded(): bool |
|
| 2780 | |||
| 2781 | 1 | private static function mbstring_overloaded(): bool |
|
| 2782 | { |
||
| 2783 | return \defined('MB_OVERLOAD_STRING') |
||
| 2784 | && |
||
| 2785 | 1 | \ini_get('mbstring.func_overload') & MB_OVERLOAD_STRING; |
|
| 2786 | } |
||
| 2787 | |||
| 2788 | /** |
||
| 2789 | * Returns the UTF-8 character with the minimum code point in the given data. |
||
| 2790 | * |
||
| 2791 | * @param mixed $arg <strong>A UTF-8 encoded string or an array of such strings.</strong> |
||
| 2792 | * |
||
| 2793 | * @return string <p>The character with the lowest code point than others.</p> |
||
| 2794 | */ |
||
| 2795 | 1 | View Code Duplication | public static function min($arg): string |
| 2803 | |||
| 2804 | /** |
||
| 2805 | * alias for "UTF8::normalize_encoding()" |
||
| 2806 | * |
||
| 2807 | * @see UTF8::normalize_encoding() |
||
| 2808 | * |
||
| 2809 | * @param string $encoding |
||
| 2810 | * @param mixed $fallback |
||
| 2811 | * |
||
| 2812 | * @return string |
||
| 2813 | * |
||
| 2814 | * @deprecated <p>use "UTF8::normalize_encoding()"</p> |
||
| 2815 | */ |
||
| 2816 | 1 | public static function normalizeEncoding(string $encoding, $fallback = '') |
|
| 2820 | |||
| 2821 | /** |
||
| 2822 | * Normalize the encoding-"name" input. |
||
| 2823 | * |
||
| 2824 | * @param string $encoding <p>e.g.: ISO, UTF8, WINDOWS-1251 etc.</p> |
||
| 2825 | * @param mixed $fallback <p>e.g.: UTF-8</p> |
||
| 2826 | * |
||
| 2827 | * @return string <p>e.g.: ISO-8859-1, UTF-8, WINDOWS-1251 etc.<br>Will return a empty string as fallback (by |
||
| 2828 | * default)</p> |
||
| 2829 | */ |
||
| 2830 | 77 | public static function normalize_encoding(string $encoding, $fallback = '') |
|
| 2938 | |||
| 2939 | /** |
||
| 2940 | * Normalize some MS Word special characters. |
||
| 2941 | * |
||
| 2942 | * @param string $str <p>The string to be normalized.</p> |
||
| 2943 | * |
||
| 2944 | * @return string |
||
| 2945 | */ |
||
| 2946 | 16 | View Code Duplication | public static function normalize_msword(string $str): string |
| 2968 | |||
| 2969 | /** |
||
| 2970 | * Normalize the whitespace. |
||
| 2971 | * |
||
| 2972 | * @param string $str <p>The string to be normalized.</p> |
||
| 2973 | * @param bool $keepNonBreakingSpace [optional] <p>Set to true, to keep non-breaking-spaces.</p> |
||
| 2974 | * @param bool $keepBidiUnicodeControls [optional] <p>Set to true, to keep non-printable (for the web) |
||
| 2975 | * bidirectional text chars.</p> |
||
| 2976 | * |
||
| 2977 | * @return string |
||
| 2978 | */ |
||
| 2979 | 38 | public static function normalize_whitespace(string $str, bool $keepNonBreakingSpace = false, bool $keepBidiUnicodeControls = false): string |
|
| 3011 | |||
| 3012 | /** |
||
| 3013 | * Strip all whitespace characters. This includes tabs and newline |
||
| 3014 | * characters, as well as multibyte whitespace such as the thin space |
||
| 3015 | * and ideographic space. |
||
| 3016 | * |
||
| 3017 | * @param string $str |
||
| 3018 | * |
||
| 3019 | * @return string |
||
| 3020 | */ |
||
| 3021 | 12 | public static function strip_whitespace(string $str): string |
|
| 3029 | |||
| 3030 | /** |
||
| 3031 | * Calculates Unicode code point of the given UTF-8 encoded character. |
||
| 3032 | * |
||
| 3033 | * INFO: opposite to UTF8::chr() |
||
| 3034 | * |
||
| 3035 | * @param string $chr <p>The character of which to calculate code point.<p/> |
||
| 3036 | * @param string $encoding [optional] <p>Default is UTF-8</p> |
||
| 3037 | * |
||
| 3038 | * @return int <p> |
||
| 3039 | * Unicode code point of the given character,<br> |
||
| 3040 | * 0 on invalid UTF-8 byte sequence. |
||
| 3041 | * </p> |
||
| 3042 | */ |
||
| 3043 | 23 | public static function ord(string $chr, string $encoding = 'UTF-8'): int |
|
| 3095 | |||
| 3096 | /** |
||
| 3097 | * Parses the string into an array (into the the second parameter). |
||
| 3098 | * |
||
| 3099 | * WARNING: Instead of "parse_str()" this method do not (re-)placing variables in the current scope, |
||
| 3100 | * if the second parameter is not set! |
||
| 3101 | * |
||
| 3102 | * @link http://php.net/manual/en/function.parse-str.php |
||
| 3103 | * |
||
| 3104 | * @param string $str <p>The input string.</p> |
||
| 3105 | * @param array $result <p>The result will be returned into this reference parameter.</p> |
||
| 3106 | * @param bool $cleanUtf8 [optional] <p>Remove non UTF-8 chars from the string.</p> |
||
| 3107 | * |
||
| 3108 | * @return bool <p>Will return <strong>false</strong> if php can't parse the string and we haven't any $result.</p> |
||
| 3109 | */ |
||
| 3110 | 1 | public static function parse_str(string $str, &$result, bool $cleanUtf8 = false): bool |
|
| 3121 | |||
| 3122 | /** |
||
| 3123 | * Checks if \u modifier is available that enables Unicode support in PCRE. |
||
| 3124 | * |
||
| 3125 | * @return bool <p><strong>true</strong> if support is available, <strong>false</strong> otherwise.</p> |
||
| 3126 | */ |
||
| 3127 | 59 | public static function pcre_utf8_support(): bool |
|
| 3132 | |||
| 3133 | /** |
||
| 3134 | * Create an array containing a range of UTF-8 characters. |
||
| 3135 | * |
||
| 3136 | * @param mixed $var1 <p>Numeric or hexadecimal code points, or a UTF-8 character to start from.</p> |
||
| 3137 | * @param mixed $var2 <p>Numeric or hexadecimal code points, or a UTF-8 character to end at.</p> |
||
| 3138 | * |
||
| 3139 | * @return array |
||
| 3140 | */ |
||
| 3141 | 1 | public static function range($var1, $var2): array |
|
| 3179 | |||
| 3180 | /** |
||
| 3181 | * Multi decode html entity & fix urlencoded-win1252-chars. |
||
| 3182 | * |
||
| 3183 | * e.g: |
||
| 3184 | * 'test+test' => 'test+test' |
||
| 3185 | * 'Düsseldorf' => 'Düsseldorf' |
||
| 3186 | * 'D%FCsseldorf' => 'Düsseldorf' |
||
| 3187 | * 'Düsseldorf' => 'Düsseldorf' |
||
| 3188 | * 'D%26%23xFC%3Bsseldorf' => 'Düsseldorf' |
||
| 3189 | * 'Düsseldorf' => 'Düsseldorf' |
||
| 3190 | * 'D%C3%BCsseldorf' => 'Düsseldorf' |
||
| 3191 | * 'D%C3%83%C2%BCsseldorf' => 'Düsseldorf' |
||
| 3192 | * 'D%25C3%2583%25C2%25BCsseldorf' => 'Düsseldorf' |
||
| 3193 | * |
||
| 3194 | * @param string $str <p>The input string.</p> |
||
| 3195 | * @param bool $multi_decode <p>Decode as often as possible.</p> |
||
| 3196 | * |
||
| 3197 | * @return string |
||
| 3198 | */ |
||
| 3199 | 2 | View Code Duplication | public static function rawurldecode(string $str, bool $multi_decode = true): string |
| 3228 | |||
| 3229 | /** |
||
| 3230 | * alias for "UTF8::remove_bom()" |
||
| 3231 | * |
||
| 3232 | * @see UTF8::remove_bom() |
||
| 3233 | * |
||
| 3234 | * @param string $str |
||
| 3235 | * |
||
| 3236 | * @return string |
||
| 3237 | * |
||
| 3238 | * @deprecated <p>use "UTF8::remove_bom()"</p> |
||
| 3239 | */ |
||
| 3240 | public static function removeBOM(string $str): string |
||
| 3244 | |||
| 3245 | /** |
||
| 3246 | * Remove the BOM from UTF-8 / UTF-16 / UTF-32 strings. |
||
| 3247 | * |
||
| 3248 | * @param string $str <p>The input string.</p> |
||
| 3249 | * |
||
| 3250 | * @return string <p>String without UTF-BOM</p> |
||
| 3251 | */ |
||
| 3252 | 41 | public static function remove_bom(string $str): string |
|
| 3270 | |||
| 3271 | /** |
||
| 3272 | * Removes duplicate occurrences of a string in another string. |
||
| 3273 | * |
||
| 3274 | * @param string $str <p>The base string.</p> |
||
| 3275 | * @param string|string[] $what <p>String to search for in the base string.</p> |
||
| 3276 | * |
||
| 3277 | * @return string <p>The result string with removed duplicates.</p> |
||
| 3278 | */ |
||
| 3279 | 1 | public static function remove_duplicates(string $str, $what = ' '): string |
|
| 3294 | |||
| 3295 | /** |
||
| 3296 | * Remove invisible characters from a string. |
||
| 3297 | * |
||
| 3298 | * e.g.: This prevents sandwiching null characters between ascii characters, like Java\0script. |
||
| 3299 | * |
||
| 3300 | * copy&past from https://github.com/bcit-ci/CodeIgniter/blob/develop/system/core/Common.php |
||
| 3301 | * |
||
| 3302 | * @param string $str |
||
| 3303 | * @param bool $url_encoded |
||
| 3304 | * @param string $replacement |
||
| 3305 | * |
||
| 3306 | * @return string |
||
| 3307 | */ |
||
| 3308 | 63 | public static function remove_invisible_characters(string $str, bool $url_encoded = true, string $replacement = ''): string |
|
| 3328 | |||
| 3329 | /** |
||
| 3330 | * Replace the diamond question mark (�) and invalid-UTF8 chars with the replacement. |
||
| 3331 | * |
||
| 3332 | * @param string $str <p>The input string</p> |
||
| 3333 | * @param string $replacementChar <p>The replacement character.</p> |
||
| 3334 | * @param bool $processInvalidUtf8 <p>Convert invalid UTF-8 chars </p> |
||
| 3335 | * |
||
| 3336 | * @return string |
||
| 3337 | */ |
||
| 3338 | 63 | public static function replace_diamond_question_mark(string $str, string $replacementChar = '', bool $processInvalidUtf8 = true): string |
|
| 3378 | |||
| 3379 | /** |
||
| 3380 | * Strip whitespace or other characters from end of a UTF-8 string. |
||
| 3381 | * |
||
| 3382 | * @param string $str <p>The string to be trimmed.</p> |
||
| 3383 | * @param mixed $chars <p>Optional characters to be stripped.</p> |
||
| 3384 | * |
||
| 3385 | * @return string <p>The string with unwanted characters stripped from the right.</p> |
||
| 3386 | */ |
||
| 3387 | 23 | View Code Duplication | public static function rtrim(string $str = '', $chars = INF): string |
| 3400 | |||
| 3401 | /** |
||
| 3402 | * rxClass |
||
| 3403 | * |
||
| 3404 | * @param string $s |
||
| 3405 | * @param string $class |
||
| 3406 | * |
||
| 3407 | * @return string |
||
| 3408 | */ |
||
| 3409 | 60 | private static function rxClass(string $s, string $class = ''): string |
|
| 3449 | |||
| 3450 | /** |
||
| 3451 | * WARNING: Print native UTF-8 support (libs), e.g. for debugging. |
||
| 3452 | */ |
||
| 3453 | 1 | public static function showSupport() |
|
| 3465 | |||
| 3466 | /** |
||
| 3467 | * Converts a UTF-8 character to HTML Numbered Entity like "{". |
||
| 3468 | * |
||
| 3469 | * @param string $char <p>The Unicode character to be encoded as numbered entity.</p> |
||
| 3470 | * @param bool $keepAsciiChars <p>Set to <strong>true</strong> to keep ASCII chars.</> |
||
| 3471 | * @param string $encoding [optional] <p>Default is UTF-8</p> |
||
| 3472 | * |
||
| 3473 | * @return string <p>The HTML numbered entity.</p> |
||
| 3474 | */ |
||
| 3475 | 1 | public static function single_chr_html_encode(string $char, bool $keepAsciiChars = false, string $encoding = 'UTF-8'): string |
|
| 3495 | |||
| 3496 | /** |
||
| 3497 | * Convert a string to an array of Unicode characters. |
||
| 3498 | * |
||
| 3499 | * @param string $str <p>The string to split into array.</p> |
||
| 3500 | * @param int $length [optional] <p>Max character length of each array element.</p> |
||
| 3501 | * @param bool $cleanUtf8 [optional] <p>Remove non UTF-8 chars from the string.</p> |
||
| 3502 | * |
||
| 3503 | * @return string[] <p>An array containing chunks of the string.</p> |
||
| 3504 | */ |
||
| 3505 | 39 | public static function split(string $str, int $length = 1, bool $cleanUtf8 = false): array |
|
| 3613 | |||
| 3614 | /** |
||
| 3615 | * Optimized "\mb_detect_encoding()"-function -> with support for UTF-16 and UTF-32. |
||
| 3616 | * |
||
| 3617 | * @param string $str <p>The input string.</p> |
||
| 3618 | * |
||
| 3619 | * @return false|string <p> |
||
| 3620 | * The detected string-encoding e.g. UTF-8 or UTF-16BE,<br> |
||
| 3621 | * otherwise it will return false. |
||
| 3622 | * </p> |
||
| 3623 | */ |
||
| 3624 | 14 | public static function str_detect_encoding(string $str) |
|
| 3718 | |||
| 3719 | /** |
||
| 3720 | * Check if the string ends with the given substring. |
||
| 3721 | * |
||
| 3722 | * @param string $haystack <p>The string to search in.</p> |
||
| 3723 | * @param string $needle <p>The substring to search for.</p> |
||
| 3724 | * |
||
| 3725 | * @return bool |
||
| 3726 | */ |
||
| 3727 | 2 | View Code Duplication | public static function str_ends_with(string $haystack, string $needle): bool |
| 3739 | |||
| 3740 | /** |
||
| 3741 | * Check if the string ends with the given substring, case insensitive. |
||
| 3742 | * |
||
| 3743 | * @param string $haystack <p>The string to search in.</p> |
||
| 3744 | * @param string $needle <p>The substring to search for.</p> |
||
| 3745 | * |
||
| 3746 | * @return bool |
||
| 3747 | */ |
||
| 3748 | 2 | View Code Duplication | public static function str_iends_with(string $haystack, string $needle): bool |
| 3760 | |||
| 3761 | /** |
||
| 3762 | * Case-insensitive and UTF-8 safe version of <function>str_replace</function>. |
||
| 3763 | * |
||
| 3764 | * @link http://php.net/manual/en/function.str-ireplace.php |
||
| 3765 | * |
||
| 3766 | * @param mixed $search <p> |
||
| 3767 | * Every replacement with search array is |
||
| 3768 | * performed on the result of previous replacement. |
||
| 3769 | * </p> |
||
| 3770 | * @param mixed $replace <p> |
||
| 3771 | * </p> |
||
| 3772 | * @param mixed $subject <p> |
||
| 3773 | * If subject is an array, then the search and |
||
| 3774 | * replace is performed with every entry of |
||
| 3775 | * subject, and the return value is an array as |
||
| 3776 | * well. |
||
| 3777 | * </p> |
||
| 3778 | * @param int $count [optional] <p> |
||
| 3779 | * The number of matched and replaced needles will |
||
| 3780 | * be returned in count which is passed by |
||
| 3781 | * reference. |
||
| 3782 | * </p> |
||
| 3783 | * |
||
| 3784 | * @return mixed <p>A string or an array of replacements.</p> |
||
| 3785 | */ |
||
| 3786 | 26 | public static function str_ireplace($search, $replace, $subject, &$count = null) |
|
| 3804 | |||
| 3805 | /** |
||
| 3806 | * Check if the string starts with the given substring, case insensitive. |
||
| 3807 | * |
||
| 3808 | * @param string $haystack <p>The string to search in.</p> |
||
| 3809 | * @param string $needle <p>The substring to search for.</p> |
||
| 3810 | * |
||
| 3811 | * @return bool |
||
| 3812 | */ |
||
| 3813 | 2 | View Code Duplication | public static function str_istarts_with(string $haystack, string $needle): bool |
| 3825 | |||
| 3826 | /** |
||
| 3827 | * Limit the number of characters in a string, but also after the next word. |
||
| 3828 | * |
||
| 3829 | * @param string $str |
||
| 3830 | * @param int $length |
||
| 3831 | * @param string $strAddOn |
||
| 3832 | * |
||
| 3833 | * @return string |
||
| 3834 | */ |
||
| 3835 | 1 | public static function str_limit_after_word(string $str, int $length = 100, string $strAddOn = '…'): string |
|
| 3862 | |||
| 3863 | /** |
||
| 3864 | * Pad a UTF-8 string to given length with another string. |
||
| 3865 | * |
||
| 3866 | * @param string $str <p>The input string.</p> |
||
| 3867 | * @param int $pad_length <p>The length of return string.</p> |
||
| 3868 | * @param string $pad_string [optional] <p>String to use for padding the input string.</p> |
||
| 3869 | * @param int $pad_type [optional] <p> |
||
| 3870 | * Can be <strong>STR_PAD_RIGHT</strong> (default), |
||
| 3871 | * <strong>STR_PAD_LEFT</strong> or <strong>STR_PAD_BOTH</strong> |
||
| 3872 | * </p> |
||
| 3873 | * |
||
| 3874 | * @return string <strong>Returns the padded string</strong> |
||
| 3875 | */ |
||
| 3876 | 2 | public static function str_pad(string $str, int $pad_length, string $pad_string = ' ', int $pad_type = STR_PAD_RIGHT): string |
|
| 3917 | |||
| 3918 | /** |
||
| 3919 | * Repeat a string. |
||
| 3920 | * |
||
| 3921 | * @param string $str <p> |
||
| 3922 | * The string to be repeated. |
||
| 3923 | * </p> |
||
| 3924 | * @param int $multiplier <p> |
||
| 3925 | * Number of time the input string should be |
||
| 3926 | * repeated. |
||
| 3927 | * </p> |
||
| 3928 | * <p> |
||
| 3929 | * multiplier has to be greater than or equal to 0. |
||
| 3930 | * If the multiplier is set to 0, the function |
||
| 3931 | * will return an empty string. |
||
| 3932 | * </p> |
||
| 3933 | * |
||
| 3934 | * @return string <p>The repeated string.</p> |
||
| 3935 | */ |
||
| 3936 | 1 | public static function str_repeat(string $str, int $multiplier): string |
|
| 3942 | |||
| 3943 | /** |
||
| 3944 | * INFO: This is only a wrapper for "str_replace()" -> the original functions is already UTF-8 safe. |
||
| 3945 | * |
||
| 3946 | * Replace all occurrences of the search string with the replacement string |
||
| 3947 | * |
||
| 3948 | * @link http://php.net/manual/en/function.str-replace.php |
||
| 3949 | * |
||
| 3950 | * @param mixed $search <p> |
||
| 3951 | * The value being searched for, otherwise known as the needle. |
||
| 3952 | * An array may be used to designate multiple needles. |
||
| 3953 | * </p> |
||
| 3954 | * @param mixed $replace <p> |
||
| 3955 | * The replacement value that replaces found search |
||
| 3956 | * values. An array may be used to designate multiple replacements. |
||
| 3957 | * </p> |
||
| 3958 | * @param mixed $subject <p> |
||
| 3959 | * The string or array being searched and replaced on, |
||
| 3960 | * otherwise known as the haystack. |
||
| 3961 | * </p> |
||
| 3962 | * <p> |
||
| 3963 | * If subject is an array, then the search and |
||
| 3964 | * replace is performed with every entry of |
||
| 3965 | * subject, and the return value is an array as |
||
| 3966 | * well. |
||
| 3967 | * </p> |
||
| 3968 | * @param int $count [optional] If passed, this will hold the number of matched and replaced needles. |
||
| 3969 | * |
||
| 3970 | * @return mixed <p>This function returns a string or an array with the replaced values.</p> |
||
| 3971 | */ |
||
| 3972 | 12 | public static function str_replace($search, $replace, $subject, int &$count = null) |
|
| 3976 | |||
| 3977 | /** |
||
| 3978 | * Replace the first "$search"-term with the "$replace"-term. |
||
| 3979 | * |
||
| 3980 | * @param string $search |
||
| 3981 | * @param string $replace |
||
| 3982 | * @param string $subject |
||
| 3983 | * |
||
| 3984 | * @return string |
||
| 3985 | */ |
||
| 3986 | 1 | public static function str_replace_first(string $search, string $replace, string $subject): string |
|
| 3996 | |||
| 3997 | /** |
||
| 3998 | * Shuffles all the characters in the string. |
||
| 3999 | * |
||
| 4000 | * @param string $str <p>The input string</p> |
||
| 4001 | * |
||
| 4002 | * @return string <p>The shuffled string.</p> |
||
| 4003 | */ |
||
| 4004 | 1 | public static function str_shuffle(string $str): string |
|
| 4012 | |||
| 4013 | /** |
||
| 4014 | * Sort all characters according to code points. |
||
| 4015 | * |
||
| 4016 | * @param string $str <p>A UTF-8 string.</p> |
||
| 4017 | * @param bool $unique <p>Sort unique. If <strong>true</strong>, repeated characters are ignored.</p> |
||
| 4018 | * @param bool $desc <p>If <strong>true</strong>, will sort characters in reverse code point order.</p> |
||
| 4019 | * |
||
| 4020 | * @return string <p>String of sorted characters.</p> |
||
| 4021 | */ |
||
| 4022 | 1 | public static function str_sort(string $str, bool $unique = false, bool $desc = false): string |
|
| 4038 | |||
| 4039 | /** |
||
| 4040 | * Split a string into an array. |
||
| 4041 | * |
||
| 4042 | * @param string|string[] $str |
||
| 4043 | * @param int $len |
||
| 4044 | * |
||
| 4045 | * @return array |
||
| 4046 | */ |
||
| 4047 | 23 | public static function str_split($str, int $len = 1): array |
|
| 4087 | |||
| 4088 | /** |
||
| 4089 | * Check if the string starts with the given substring. |
||
| 4090 | * |
||
| 4091 | * @param string $haystack <p>The string to search in.</p> |
||
| 4092 | * @param string $needle <p>The substring to search for.</p> |
||
| 4093 | * |
||
| 4094 | * @return bool |
||
| 4095 | */ |
||
| 4096 | 2 | View Code Duplication | public static function str_starts_with(string $haystack, string $needle): bool |
| 4108 | |||
| 4109 | /** |
||
| 4110 | * Get a binary representation of a specific string. |
||
| 4111 | * |
||
| 4112 | * @param string $str <p>The input string.</p> |
||
| 4113 | * |
||
| 4114 | * @return string |
||
| 4115 | */ |
||
| 4116 | 1 | public static function str_to_binary(string $str): string |
|
| 4122 | |||
| 4123 | /** |
||
| 4124 | * Convert a string into an array of words. |
||
| 4125 | * |
||
| 4126 | * @param string $str |
||
| 4127 | * @param string $charList <p>Additional chars for the definition of "words".</p> |
||
| 4128 | * @param bool $removeEmptyValues <p>Remove empty values.</p> |
||
| 4129 | * @param null|int $removeShortValues |
||
| 4130 | * |
||
| 4131 | * @return array |
||
| 4132 | */ |
||
| 4133 | 10 | public static function str_to_words(string $str, string $charList = '', bool $removeEmptyValues = false, int $removeShortValues = null): array |
|
| 4178 | |||
| 4179 | /** |
||
| 4180 | * alias for "UTF8::to_ascii()" |
||
| 4181 | * |
||
| 4182 | * @see UTF8::to_ascii() |
||
| 4183 | * |
||
| 4184 | * @param string $str |
||
| 4185 | * @param string $unknown |
||
| 4186 | * @param bool $strict |
||
| 4187 | * |
||
| 4188 | * @return string |
||
| 4189 | */ |
||
| 4190 | 7 | public static function str_transliterate(string $str, string $unknown = '?', bool $strict = false): string |
|
| 4194 | |||
| 4195 | /** |
||
| 4196 | * Counts number of words in the UTF-8 string. |
||
| 4197 | * |
||
| 4198 | * @param string $str <p>The input string.</p> |
||
| 4199 | * @param int $format [optional] <p> |
||
| 4200 | * <strong>0</strong> => return a number of words (default)<br> |
||
| 4201 | * <strong>1</strong> => return an array of words<br> |
||
| 4202 | * <strong>2</strong> => return an array of words with word-offset as key |
||
| 4203 | * </p> |
||
| 4204 | * @param string $charlist [optional] <p>Additional chars that contains to words and do not start a new word.</p> |
||
| 4205 | * |
||
| 4206 | * @return array|int <p>The number of words in the string</p> |
||
| 4207 | */ |
||
| 4208 | 1 | public static function str_word_count(string $str, int $format = 0, string $charlist = '') |
|
| 4238 | |||
| 4239 | /** |
||
| 4240 | * Case-insensitive string comparison. |
||
| 4241 | * |
||
| 4242 | * INFO: Case-insensitive version of UTF8::strcmp() |
||
| 4243 | * |
||
| 4244 | * @param string $str1 |
||
| 4245 | * @param string $str2 |
||
| 4246 | * |
||
| 4247 | * @return int <p> |
||
| 4248 | * <strong>< 0</strong> if str1 is less than str2;<br> |
||
| 4249 | * <strong>> 0</strong> if str1 is greater than str2,<br> |
||
| 4250 | * <strong>0</strong> if they are equal. |
||
| 4251 | * </p> |
||
| 4252 | */ |
||
| 4253 | 11 | public static function strcasecmp(string $str1, string $str2): int |
|
| 4257 | |||
| 4258 | /** |
||
| 4259 | * alias for "UTF8::strstr()" |
||
| 4260 | * |
||
| 4261 | * @see UTF8::strstr() |
||
| 4262 | * |
||
| 4263 | * @param string $haystack |
||
| 4264 | * @param string $needle |
||
| 4265 | * @param bool $before_needle |
||
| 4266 | * @param string $encoding |
||
| 4267 | * @param bool $cleanUtf8 |
||
| 4268 | * |
||
| 4269 | * @return string|false |
||
| 4270 | */ |
||
| 4271 | 1 | public static function strchr(string $haystack, string $needle, bool $before_needle = false, string $encoding = 'UTF-8', bool $cleanUtf8 = false) |
|
| 4275 | |||
| 4276 | /** |
||
| 4277 | * Case-sensitive string comparison. |
||
| 4278 | * |
||
| 4279 | * @param string $str1 |
||
| 4280 | * @param string $str2 |
||
| 4281 | * |
||
| 4282 | * @return int <p> |
||
| 4283 | * <strong>< 0</strong> if str1 is less than str2<br> |
||
| 4284 | * <strong>> 0</strong> if str1 is greater than str2<br> |
||
| 4285 | * <strong>0</strong> if they are equal. |
||
| 4286 | * </p> |
||
| 4287 | */ |
||
| 4288 | 14 | public static function strcmp(string $str1, string $str2): int |
|
| 4296 | |||
| 4297 | /** |
||
| 4298 | * Find length of initial segment not matching mask. |
||
| 4299 | * |
||
| 4300 | * @param string $str |
||
| 4301 | * @param string $charList |
||
| 4302 | * @param int $offset |
||
| 4303 | * @param int $length |
||
| 4304 | * |
||
| 4305 | * @return int|null |
||
| 4306 | */ |
||
| 4307 | 15 | public static function strcspn(string $str, string $charList, int $offset = 0, int $length = null) |
|
| 4331 | |||
| 4332 | /** |
||
| 4333 | * alias for "UTF8::stristr()" |
||
| 4334 | * |
||
| 4335 | * @see UTF8::stristr() |
||
| 4336 | * |
||
| 4337 | * @param string $haystack |
||
| 4338 | * @param string $needle |
||
| 4339 | * @param bool $before_needle |
||
| 4340 | * @param string $encoding |
||
| 4341 | * @param bool $cleanUtf8 |
||
| 4342 | * |
||
| 4343 | * @return string|false |
||
| 4344 | */ |
||
| 4345 | 1 | public static function strichr(string $haystack, string $needle, bool $before_needle = false, string $encoding = 'UTF-8', bool $cleanUtf8 = false) |
|
| 4349 | |||
| 4350 | /** |
||
| 4351 | * Create a UTF-8 string from code points. |
||
| 4352 | * |
||
| 4353 | * INFO: opposite to UTF8::codepoints() |
||
| 4354 | * |
||
| 4355 | * @param array $array <p>Integer or Hexadecimal codepoints.</p> |
||
| 4356 | * |
||
| 4357 | * @return string <p>UTF-8 encoded string.</p> |
||
| 4358 | */ |
||
| 4359 | 2 | public static function string(array $array): string |
|
| 4372 | |||
| 4373 | /** |
||
| 4374 | * Checks if string starts with "BOM" (Byte Order Mark Character) character. |
||
| 4375 | * |
||
| 4376 | * @param string $str <p>The input string.</p> |
||
| 4377 | * |
||
| 4378 | * @return bool <p><strong>true</strong> if the string has BOM at the start, <strong>false</strong> otherwise.</p> |
||
| 4379 | */ |
||
| 4380 | 3 | public static function string_has_bom(string $str): bool |
|
| 4390 | |||
| 4391 | /** |
||
| 4392 | * Strip HTML and PHP tags from a string + clean invalid UTF-8. |
||
| 4393 | * |
||
| 4394 | * @link http://php.net/manual/en/function.strip-tags.php |
||
| 4395 | * |
||
| 4396 | * @param string $str <p> |
||
| 4397 | * The input string. |
||
| 4398 | * </p> |
||
| 4399 | * @param string $allowable_tags [optional] <p> |
||
| 4400 | * You can use the optional second parameter to specify tags which should |
||
| 4401 | * not be stripped. |
||
| 4402 | * </p> |
||
| 4403 | * <p> |
||
| 4404 | * HTML comments and PHP tags are also stripped. This is hardcoded and |
||
| 4405 | * can not be changed with allowable_tags. |
||
| 4406 | * </p> |
||
| 4407 | * @param bool $cleanUtf8 [optional] <p>Remove non UTF-8 chars from the string.</p> |
||
| 4408 | * |
||
| 4409 | * @return string <p>The stripped string.</p> |
||
| 4410 | */ |
||
| 4411 | 2 | public static function strip_tags(string $str, string $allowable_tags = null, bool $cleanUtf8 = false): string |
|
| 4423 | |||
| 4424 | /** |
||
| 4425 | * Finds position of first occurrence of a string within another, case insensitive. |
||
| 4426 | * |
||
| 4427 | * @link http://php.net/manual/en/function.mb-stripos.php |
||
| 4428 | * |
||
| 4429 | * @param string $haystack <p>The string from which to get the position of the first occurrence of needle.</p> |
||
| 4430 | * @param string $needle <p>The string to find in haystack.</p> |
||
| 4431 | * @param int $offset [optional] <p>The position in haystack to start searching.</p> |
||
| 4432 | * @param string $encoding [optional] <p>Set the charset.</p> |
||
| 4433 | * @param bool $cleanUtf8 [optional] <p>Remove non UTF-8 chars from the string.</p> |
||
| 4434 | * |
||
| 4435 | * @return int|false <p> |
||
| 4436 | * Return the numeric position of the first occurrence of needle in the haystack string,<br> |
||
| 4437 | * or false if needle is not found. |
||
| 4438 | * </p> |
||
| 4439 | */ |
||
| 4440 | 10 | public static function stripos(string $haystack, string $needle, int $offset = 0, string $encoding = 'UTF-8', bool $cleanUtf8 = false) |
|
| 4472 | |||
| 4473 | /** |
||
| 4474 | * Returns all of haystack starting from and including the first occurrence of needle to the end. |
||
| 4475 | * |
||
| 4476 | * @param string $haystack <p>The input string. Must be valid UTF-8.</p> |
||
| 4477 | * @param string $needle <p>The string to look for. Must be valid UTF-8.</p> |
||
| 4478 | * @param bool $before_needle [optional] <p> |
||
| 4479 | * If <b>TRUE</b>, grapheme_strstr() returns the part of the |
||
| 4480 | * haystack before the first occurrence of the needle (excluding the needle). |
||
| 4481 | * </p> |
||
| 4482 | * @param string $encoding [optional] <p>Set the charset for e.g. "\mb_" function</p> |
||
| 4483 | * @param bool $cleanUtf8 [optional] <p>Remove non UTF-8 chars from the string.</p> |
||
| 4484 | * |
||
| 4485 | * @return false|string A sub-string,<br>or <strong>false</strong> if needle is not found. |
||
| 4486 | */ |
||
| 4487 | 17 | public static function stristr(string $haystack, string $needle, bool $before_needle = false, string $encoding = 'UTF-8', bool $cleanUtf8 = false) |
|
| 4548 | |||
| 4549 | /** |
||
| 4550 | * Get the string length, not the byte-length! |
||
| 4551 | * |
||
| 4552 | * @link http://php.net/manual/en/function.mb-strlen.php |
||
| 4553 | * |
||
| 4554 | * @param string $str <p>The string being checked for length.</p> |
||
| 4555 | * @param string $encoding [optional] <p>Set the charset.</p> |
||
| 4556 | * @param bool $cleanUtf8 [optional] <p>Remove non UTF-8 chars from the string.</p> |
||
| 4557 | * |
||
| 4558 | * @return int <p>The number of characters in the string $str having character encoding $encoding. (One multi-byte |
||
| 4559 | * character counted as +1)</p> |
||
| 4560 | */ |
||
| 4561 | 89 | public static function strlen(string $str, string $encoding = 'UTF-8', bool $cleanUtf8 = false): int |
|
| 4655 | |||
| 4656 | /** |
||
| 4657 | * Get string length in byte. |
||
| 4658 | * |
||
| 4659 | * @param string $str |
||
| 4660 | * |
||
| 4661 | * @return int |
||
| 4662 | */ |
||
| 4663 | 70 | public static function strlen_in_byte(string $str): int |
|
| 4673 | |||
| 4674 | /** |
||
| 4675 | * Case insensitive string comparisons using a "natural order" algorithm. |
||
| 4676 | * |
||
| 4677 | * INFO: natural order version of UTF8::strcasecmp() |
||
| 4678 | * |
||
| 4679 | * @param string $str1 <p>The first string.</p> |
||
| 4680 | * @param string $str2 <p>The second string.</p> |
||
| 4681 | * |
||
| 4682 | * @return int <strong>< 0</strong> if str1 is less than str2<br> |
||
| 4683 | * <strong>> 0</strong> if str1 is greater than str2<br> |
||
| 4684 | * <strong>0</strong> if they are equal |
||
| 4685 | */ |
||
| 4686 | 1 | public static function strnatcasecmp(string $str1, string $str2): int |
|
| 4690 | |||
| 4691 | /** |
||
| 4692 | * String comparisons using a "natural order" algorithm |
||
| 4693 | * |
||
| 4694 | * INFO: natural order version of UTF8::strcmp() |
||
| 4695 | * |
||
| 4696 | * @link http://php.net/manual/en/function.strnatcmp.php |
||
| 4697 | * |
||
| 4698 | * @param string $str1 <p>The first string.</p> |
||
| 4699 | * @param string $str2 <p>The second string.</p> |
||
| 4700 | * |
||
| 4701 | * @return int <strong>< 0</strong> if str1 is less than str2;<br> |
||
| 4702 | * <strong>> 0</strong> if str1 is greater than str2;<br> |
||
| 4703 | * <strong>0</strong> if they are equal |
||
| 4704 | */ |
||
| 4705 | 2 | public static function strnatcmp(string $str1, string $str2): int |
|
| 4709 | |||
| 4710 | /** |
||
| 4711 | * Case-insensitive string comparison of the first n characters. |
||
| 4712 | * |
||
| 4713 | * @link http://php.net/manual/en/function.strncasecmp.php |
||
| 4714 | * |
||
| 4715 | * @param string $str1 <p>The first string.</p> |
||
| 4716 | * @param string $str2 <p>The second string.</p> |
||
| 4717 | * @param int $len <p>The length of strings to be used in the comparison.</p> |
||
| 4718 | * |
||
| 4719 | * @return int <strong>< 0</strong> if <i>str1</i> is less than <i>str2</i>;<br> |
||
| 4720 | * <strong>> 0</strong> if <i>str1</i> is greater than <i>str2</i>;<br> |
||
| 4721 | * <strong>0</strong> if they are equal |
||
| 4722 | */ |
||
| 4723 | 1 | public static function strncasecmp(string $str1, string $str2, int $len): int |
|
| 4727 | |||
| 4728 | /** |
||
| 4729 | * String comparison of the first n characters. |
||
| 4730 | * |
||
| 4731 | * @link http://php.net/manual/en/function.strncmp.php |
||
| 4732 | * |
||
| 4733 | * @param string $str1 <p>The first string.</p> |
||
| 4734 | * @param string $str2 <p>The second string.</p> |
||
| 4735 | * @param int $len <p>Number of characters to use in the comparison.</p> |
||
| 4736 | * |
||
| 4737 | * @return int <strong>< 0</strong> if <i>str1</i> is less than <i>str2</i>;<br> |
||
| 4738 | * <strong>> 0</strong> if <i>str1</i> is greater than <i>str2</i>;<br> |
||
| 4739 | * <strong>0</strong> if they are equal |
||
| 4740 | */ |
||
| 4741 | 2 | public static function strncmp(string $str1, string $str2, int $len): int |
|
| 4748 | |||
| 4749 | /** |
||
| 4750 | * Search a string for any of a set of characters. |
||
| 4751 | * |
||
| 4752 | * @link http://php.net/manual/en/function.strpbrk.php |
||
| 4753 | * |
||
| 4754 | * @param string $haystack <p>The string where char_list is looked for.</p> |
||
| 4755 | * @param string $char_list <p>This parameter is case sensitive.</p> |
||
| 4756 | * |
||
| 4757 | * @return string|false <p>String starting from the character found, or false if it is not found.</p> |
||
| 4758 | */ |
||
| 4759 | 1 | public static function strpbrk(string $haystack, string $char_list) |
|
| 4771 | |||
| 4772 | /** |
||
| 4773 | * Find position of first occurrence of string in a string. |
||
| 4774 | * |
||
| 4775 | * @link http://php.net/manual/en/function.mb-strpos.php |
||
| 4776 | * |
||
| 4777 | * @param string $haystack <p>The string from which to get the position of the first occurrence of needle.</p> |
||
| 4778 | * @param string $needle <p>The string to find in haystack.</p> |
||
| 4779 | * @param int $offset [optional] <p>The search offset. If it is not specified, 0 is used.</p> |
||
| 4780 | * @param string $encoding [optional] <p>Set the charset.</p> |
||
| 4781 | * @param bool $cleanUtf8 [optional] <p>Remove non UTF-8 chars from the string.</p> |
||
| 4782 | * |
||
| 4783 | * @return int|false <p> |
||
| 4784 | * The numeric position of the first occurrence of needle in the haystack string.<br> |
||
| 4785 | * If needle is not found it returns false. |
||
| 4786 | * </p> |
||
| 4787 | */ |
||
| 4788 | 57 | public static function strpos(string $haystack, string $needle, int $offset = 0, string $encoding = 'UTF-8', bool $cleanUtf8 = false) |
|
| 4911 | |||
| 4912 | /** |
||
| 4913 | * Finds the last occurrence of a character in a string within another. |
||
| 4914 | * |
||
| 4915 | * @link http://php.net/manual/en/function.mb-strrchr.php |
||
| 4916 | * |
||
| 4917 | * @param string $haystack <p>The string from which to get the last occurrence of needle.</p> |
||
| 4918 | * @param string $needle <p>The string to find in haystack</p> |
||
| 4919 | * @param bool $before_needle [optional] <p> |
||
| 4920 | * Determines which portion of haystack |
||
| 4921 | * this function returns. |
||
| 4922 | * If set to true, it returns all of haystack |
||
| 4923 | * from the beginning to the last occurrence of needle. |
||
| 4924 | * If set to false, it returns all of haystack |
||
| 4925 | * from the last occurrence of needle to the end, |
||
| 4926 | * </p> |
||
| 4927 | * @param string $encoding [optional] <p> |
||
| 4928 | * Character encoding name to use. |
||
| 4929 | * If it is omitted, internal character encoding is used. |
||
| 4930 | * </p> |
||
| 4931 | * @param bool $cleanUtf8 [optional] <p>Remove non UTF-8 chars from the string.</p> |
||
| 4932 | * |
||
| 4933 | * @return string|false The portion of haystack or false if needle is not found. |
||
| 4934 | */ |
||
| 4935 | 1 | View Code Duplication | public static function strrchr(string $haystack, string $needle, bool $before_needle = false, string $encoding = 'UTF-8', bool $cleanUtf8 = false) |
| 4951 | |||
| 4952 | /** |
||
| 4953 | * Reverses characters order in the string. |
||
| 4954 | * |
||
| 4955 | * @param string $str The input string |
||
| 4956 | * |
||
| 4957 | * @return string The string with characters in the reverse sequence |
||
| 4958 | */ |
||
| 4959 | 4 | public static function strrev(string $str): string |
|
| 4967 | |||
| 4968 | /** |
||
| 4969 | * Finds the last occurrence of a character in a string within another, case insensitive. |
||
| 4970 | * |
||
| 4971 | * @link http://php.net/manual/en/function.mb-strrichr.php |
||
| 4972 | * |
||
| 4973 | * @param string $haystack <p>The string from which to get the last occurrence of needle.</p> |
||
| 4974 | * @param string $needle <p>The string to find in haystack.</p> |
||
| 4975 | * @param bool $before_needle [optional] <p> |
||
| 4976 | * Determines which portion of haystack |
||
| 4977 | * this function returns. |
||
| 4978 | * If set to true, it returns all of haystack |
||
| 4979 | * from the beginning to the last occurrence of needle. |
||
| 4980 | * If set to false, it returns all of haystack |
||
| 4981 | * from the last occurrence of needle to the end, |
||
| 4982 | * </p> |
||
| 4983 | * @param string $encoding [optional] <p> |
||
| 4984 | * Character encoding name to use. |
||
| 4985 | * If it is omitted, internal character encoding is used. |
||
| 4986 | * </p> |
||
| 4987 | * @param bool $cleanUtf8 [optional] <p>Remove non UTF-8 chars from the string.</p> |
||
| 4988 | * |
||
| 4989 | * @return string|false <p>The portion of haystack or<br>false if needle is not found.</p> |
||
| 4990 | */ |
||
| 4991 | 1 | View Code Duplication | public static function strrichr(string $haystack, string $needle, bool $before_needle = false, string $encoding = 'UTF-8', bool $cleanUtf8 = false) |
| 5006 | |||
| 5007 | /** |
||
| 5008 | * Find position of last occurrence of a case-insensitive string. |
||
| 5009 | * |
||
| 5010 | * @param string $haystack <p>The string to look in.</p> |
||
| 5011 | * @param string $needle <p>The string to look for.</p> |
||
| 5012 | * @param int $offset [optional] <p>Number of characters to ignore in the beginning or end.</p> |
||
| 5013 | * @param string $encoding [optional] <p>Set the charset.</p> |
||
| 5014 | * @param bool $cleanUtf8 [optional] <p>Remove non UTF-8 chars from the string.</p> |
||
| 5015 | * |
||
| 5016 | * @return int|false <p> |
||
| 5017 | * The numeric position of the last occurrence of needle in the haystack string.<br>If needle is |
||
| 5018 | * not found, it returns false. |
||
| 5019 | * </p> |
||
| 5020 | */ |
||
| 5021 | 1 | public static function strripos(string $haystack, string $needle, int $offset = 0, string $encoding = 'UTF-8', bool $cleanUtf8 = false) |
|
| 5069 | |||
| 5070 | /** |
||
| 5071 | * Find position of last occurrence of a string in a string. |
||
| 5072 | * |
||
| 5073 | * @link http://php.net/manual/en/function.mb-strrpos.php |
||
| 5074 | * |
||
| 5075 | * @param string $haystack <p>The string being checked, for the last occurrence of needle</p> |
||
| 5076 | * @param string|int $needle <p>The string to find in haystack.<br>Or a code point as int.</p> |
||
| 5077 | * @param int $offset [optional] <p>May be specified to begin searching an arbitrary number of characters |
||
| 5078 | * into the string. Negative values will stop searching at an arbitrary point prior to |
||
| 5079 | * the end of the string. |
||
| 5080 | * </p> |
||
| 5081 | * @param string $encoding [optional] <p>Set the charset.</p> |
||
| 5082 | * @param bool $cleanUtf8 [optional] <p>Remove non UTF-8 chars from the string.</p> |
||
| 5083 | * |
||
| 5084 | * @return int|false <p>The numeric position of the last occurrence of needle in the haystack string.<br>If needle |
||
| 5085 | * is not found, it returns false.</p> |
||
| 5086 | */ |
||
| 5087 | 10 | public static function strrpos(string $haystack, $needle, int $offset = null, string $encoding = 'UTF-8', bool $cleanUtf8 = false) |
|
| 5160 | |||
| 5161 | /** |
||
| 5162 | * Finds the length of the initial segment of a string consisting entirely of characters contained within a given |
||
| 5163 | * mask. |
||
| 5164 | * |
||
| 5165 | * @param string $str <p>The input string.</p> |
||
| 5166 | * @param string $mask <p>The mask of chars</p> |
||
| 5167 | * @param int $offset [optional] |
||
| 5168 | * @param int $length [optional] |
||
| 5169 | * |
||
| 5170 | * @return int |
||
| 5171 | */ |
||
| 5172 | 10 | public static function strspn(string $str, string $mask, int $offset = 0, int $length = null): int |
|
| 5188 | |||
| 5189 | /** |
||
| 5190 | * Returns part of haystack string from the first occurrence of needle to the end of haystack. |
||
| 5191 | * |
||
| 5192 | * @param string $haystack <p>The input string. Must be valid UTF-8.</p> |
||
| 5193 | * @param string $needle <p>The string to look for. Must be valid UTF-8.</p> |
||
| 5194 | * @param bool $before_needle [optional] <p> |
||
| 5195 | * If <b>TRUE</b>, strstr() returns the part of the |
||
| 5196 | * haystack before the first occurrence of the needle (excluding the needle). |
||
| 5197 | * </p> |
||
| 5198 | * @param string $encoding [optional] <p>Set the charset.</p> |
||
| 5199 | * @param bool $cleanUtf8 [optional] <p>Remove non UTF-8 chars from the string.</p> |
||
| 5200 | * |
||
| 5201 | * @return string|false A sub-string,<br>or <strong>false</strong> if needle is not found. |
||
| 5202 | */ |
||
| 5203 | 2 | public static function strstr(string $haystack, string $needle, bool $before_needle = false, $encoding = 'UTF-8', $cleanUtf8 = false) |
|
| 5256 | |||
| 5257 | /** |
||
| 5258 | * Unicode transformation for case-less matching. |
||
| 5259 | * |
||
| 5260 | * @link http://unicode.org/reports/tr21/tr21-5.html |
||
| 5261 | * |
||
| 5262 | * @param string $str <p>The input string.</p> |
||
| 5263 | * @param bool $full [optional] <p> |
||
| 5264 | * <b>true</b>, replace full case folding chars (default)<br> |
||
| 5265 | * <b>false</b>, use only limited static array [UTF8::$commonCaseFold] |
||
| 5266 | * </p> |
||
| 5267 | * @param bool $cleanUtf8 [optional] <p>Remove non UTF-8 chars from the string.</p> |
||
| 5268 | * |
||
| 5269 | * @return string |
||
| 5270 | */ |
||
| 5271 | 13 | public static function strtocasefold(string $str, bool $full = true, bool $cleanUtf8 = false): string |
|
| 5303 | |||
| 5304 | /** |
||
| 5305 | * Make a string lowercase. |
||
| 5306 | * |
||
| 5307 | * @link http://php.net/manual/en/function.mb-strtolower.php |
||
| 5308 | * |
||
| 5309 | * @param string $str <p>The string being lowercased.</p> |
||
| 5310 | * @param string $encoding [optional] <p>Set the charset for e.g. "\mb_" function</p> |
||
| 5311 | * @param bool $cleanUtf8 [optional] <p>Remove non UTF-8 chars from the string.</p> |
||
| 5312 | * @param string|null $lang [optional] <p>Set the language for special cases: az, el, lt, tr</p> |
||
| 5313 | * |
||
| 5314 | * @return string str with all alphabetic characters converted to lowercase. |
||
| 5315 | */ |
||
| 5316 | 25 | View Code Duplication | public static function strtolower($str, string $encoding = 'UTF-8', bool $cleanUtf8 = false, string $lang = null): string |
| 5356 | |||
| 5357 | /** |
||
| 5358 | * Generic case sensitive transformation for collation matching. |
||
| 5359 | * |
||
| 5360 | * @param string $str <p>The input string</p> |
||
| 5361 | * |
||
| 5362 | * @return string |
||
| 5363 | */ |
||
| 5364 | 3 | private static function strtonatfold(string $str): string |
|
| 5369 | |||
| 5370 | /** |
||
| 5371 | * Make a string uppercase. |
||
| 5372 | * |
||
| 5373 | * @link http://php.net/manual/en/function.mb-strtoupper.php |
||
| 5374 | * |
||
| 5375 | * @param string $str <p>The string being uppercased.</p> |
||
| 5376 | * @param string $encoding [optional] <p>Set the charset.</p> |
||
| 5377 | * @param bool $cleanUtf8 [optional] <p>Remove non UTF-8 chars from the string.</p> |
||
| 5378 | * @param string|null $lang [optional] <p>Set the language for special cases: az, el, lt, tr</p> |
||
| 5379 | * |
||
| 5380 | * @return string <p>$str with all alphabetic characters converted to uppercase.</p> |
||
| 5381 | */ |
||
| 5382 | 19 | View Code Duplication | public static function strtoupper($str, string $encoding = 'UTF-8', bool $cleanUtf8 = false, string $lang = null): string |
| 5421 | |||
| 5422 | /** |
||
| 5423 | * Translate characters or replace sub-strings. |
||
| 5424 | * |
||
| 5425 | * @link http://php.net/manual/en/function.strtr.php |
||
| 5426 | * |
||
| 5427 | * @param string $str <p>The string being translated.</p> |
||
| 5428 | * @param string|string[] $from <p>The string replacing from.</p> |
||
| 5429 | * @param string|string[] $to <p>The string being translated to to.</p> |
||
| 5430 | * |
||
| 5431 | * @return string <p> |
||
| 5432 | * This function returns a copy of str, translating all occurrences of each character in from to the |
||
| 5433 | * corresponding character in to. |
||
| 5434 | * </p> |
||
| 5435 | */ |
||
| 5436 | 1 | public static function strtr(string $str, $from, $to = INF): string |
|
| 5467 | |||
| 5468 | /** |
||
| 5469 | * Return the width of a string. |
||
| 5470 | * |
||
| 5471 | * @param string $str <p>The input string.</p> |
||
| 5472 | * @param string $encoding [optional] <p>Default is UTF-8</p> |
||
| 5473 | * @param bool $cleanUtf8 [optional] <p>Remove non UTF-8 chars from the string.</p> |
||
| 5474 | * |
||
| 5475 | * @return int |
||
| 5476 | */ |
||
| 5477 | 1 | public static function strwidth(string $str, string $encoding = 'UTF-8', bool $cleanUtf8 = false): int |
|
| 5492 | |||
| 5493 | /** |
||
| 5494 | * Changes all keys in an array. |
||
| 5495 | * |
||
| 5496 | * @param array $array <p>The array to work on</p> |
||
| 5497 | * @param int $case [optional] <p> Either <strong>CASE_UPPER</strong><br> |
||
| 5498 | * or <strong>CASE_LOWER</strong> (default)</p> |
||
| 5499 | * |
||
| 5500 | * @return array <p>An array with its keys lower or uppercased.</p> |
||
| 5501 | */ |
||
| 5502 | 1 | public static function array_change_key_case(array $array, int $case = CASE_LOWER): array |
|
| 5525 | |||
| 5526 | /** |
||
| 5527 | * Get part of a string. |
||
| 5528 | * |
||
| 5529 | * @link http://php.net/manual/en/function.mb-substr.php |
||
| 5530 | * |
||
| 5531 | * @param string $str <p>The string being checked.</p> |
||
| 5532 | * @param int $offset <p>The first position used in str.</p> |
||
| 5533 | * @param int $length [optional] <p>The maximum length of the returned string.</p> |
||
| 5534 | * @param string $encoding [optional] <p>Default is UTF-8</p> |
||
| 5535 | * @param bool $cleanUtf8 [optional] <p>Remove non UTF-8 chars from the string.</p> |
||
| 5536 | * |
||
| 5537 | * @return string|false <p>The portion of <i>str</i> specified by the <i>offset</i> and |
||
| 5538 | * <i>length</i> parameters.</p><p>If <i>str</i> is shorter than <i>offset</i> |
||
| 5539 | * characters long, <b>FALSE</b> will be returned.</p> |
||
| 5540 | */ |
||
| 5541 | 72 | public static function substr(string $str, int $offset = 0, int $length = null, string $encoding = 'UTF-8', bool $cleanUtf8 = false) |
|
| 5640 | |||
| 5641 | /** |
||
| 5642 | * Binary safe comparison of two strings from an offset, up to length characters. |
||
| 5643 | * |
||
| 5644 | * @param string $str1 <p>The main string being compared.</p> |
||
| 5645 | * @param string $str2 <p>The secondary string being compared.</p> |
||
| 5646 | * @param int $offset [optional] <p>The start position for the comparison. If negative, it starts |
||
| 5647 | * counting from the end of the string.</p> |
||
| 5648 | * @param int|null $length [optional] <p>The length of the comparison. The default value is the largest of |
||
| 5649 | * the length of the str compared to the length of main_str less the offset.</p> |
||
| 5650 | * @param bool $case_insensitivity [optional] <p>If case_insensitivity is TRUE, comparison is case |
||
| 5651 | * insensitive.</p> |
||
| 5652 | * |
||
| 5653 | * @return int <p> |
||
| 5654 | * <strong>< 0</strong> if str1 is less than str2;<br> |
||
| 5655 | * <strong>> 0</strong> if str1 is greater than str2,<br> |
||
| 5656 | * <strong>0</strong> if they are equal. |
||
| 5657 | * </p> |
||
| 5658 | */ |
||
| 5659 | 1 | public static function substr_compare(string $str1, string $str2, int $offset = 0, int $length = null, bool $case_insensitivity = false): int |
|
| 5685 | |||
| 5686 | /** |
||
| 5687 | * Count the number of substring occurrences. |
||
| 5688 | * |
||
| 5689 | * @link http://php.net/manual/en/function.substr-count.php |
||
| 5690 | * |
||
| 5691 | * @param string $haystack <p>The string to search in.</p> |
||
| 5692 | * @param string $needle <p>The substring to search for.</p> |
||
| 5693 | * @param int $offset [optional] <p>The offset where to start counting.</p> |
||
| 5694 | * @param int $length [optional] <p> |
||
| 5695 | * The maximum length after the specified offset to search for the |
||
| 5696 | * substring. It outputs a warning if the offset plus the length is |
||
| 5697 | * greater than the haystack length. |
||
| 5698 | * </p> |
||
| 5699 | * @param string $encoding <p>Set the charset.</p> |
||
| 5700 | * @param bool $cleanUtf8 [optional] <p>Remove non UTF-8 chars from the string.</p> |
||
| 5701 | * |
||
| 5702 | * @return int|false <p>This functions returns an integer or false if there isn't a string.</p> |
||
| 5703 | */ |
||
| 5704 | 1 | public static function substr_count(string $haystack, string $needle, int $offset = 0, int $length = null, string $encoding = 'UTF-8', bool $cleanUtf8 = false) |
|
| 5705 | { |
||
| 5706 | 1 | if (!isset($haystack[0], $needle[0])) { |
|
| 5707 | 1 | return false; |
|
| 5708 | } |
||
| 5709 | |||
| 5710 | 1 | if ($offset || $length !== null) { |
|
| 5711 | |||
| 5712 | 1 | if ($length === null) { |
|
| 5713 | 1 | $length = self::strlen($haystack); |
|
| 5714 | } |
||
| 5715 | |||
| 5716 | if ( |
||
| 5717 | ( |
||
| 5718 | 1 | $length !== 0 |
|
| 5719 | && |
||
| 5720 | 1 | $offset !== 0 |
|
| 5721 | ) |
||
| 5722 | && |
||
| 5723 | 1 | ($length + $offset) <= 0 |
|
| 5724 | && |
||
| 5725 | 1 | Bootup::is_php('7.1') === false // output from "substr_count()" have changed in PHP 7.1 |
|
| 5726 | ) { |
||
| 5727 | return false; |
||
| 5728 | } |
||
| 5729 | |||
| 5730 | 1 | $haystackTmp = self::substr($haystack, $offset, $length, $encoding); |
|
| 5731 | 1 | if ($haystackTmp === false) { |
|
| 5732 | $haystackTmp = ''; |
||
| 5733 | } |
||
| 5734 | 1 | $haystack = (string)$haystackTmp; |
|
| 5735 | } |
||
| 5736 | |||
| 5737 | 1 | if ($encoding !== 'UTF-8') { |
|
| 5738 | 1 | $encoding = self::normalize_encoding($encoding, 'UTF-8'); |
|
| 5739 | } |
||
| 5740 | |||
| 5741 | 1 | if ($cleanUtf8 === true) { |
|
| 5742 | // "\mb_strpos" and "\iconv_strpos" returns wrong position, |
||
| 5743 | // if invalid characters are found in $haystack before $needle |
||
| 5744 | $needle = self::clean($needle); |
||
| 5745 | $haystack = self::clean($haystack); |
||
| 5746 | } |
||
| 5747 | |||
| 5748 | 1 | if (!isset(self::$SUPPORT['already_checked_via_portable_utf8'])) { |
|
| 5749 | self::checkForSupport(); |
||
| 5750 | } |
||
| 5751 | |||
| 5752 | View Code Duplication | if ( |
|
| 5753 | 1 | $encoding !== 'UTF-8' |
|
| 5754 | && |
||
| 5755 | 1 | self::$SUPPORT['mbstring'] === false |
|
| 5756 | ) { |
||
| 5757 | \trigger_error('UTF8::substr_count() without mbstring cannot handle "' . $encoding . '" encoding', E_USER_WARNING); |
||
| 5758 | } |
||
| 5759 | |||
| 5760 | 1 | if (self::$SUPPORT['mbstring'] === true) { |
|
| 5761 | 1 | return \mb_substr_count($haystack, $needle, $encoding); |
|
| 5762 | } |
||
| 5763 | |||
| 5764 | \preg_match_all('/' . \preg_quote($needle, '/') . '/us', $haystack, $matches, PREG_SET_ORDER); |
||
| 5765 | |||
| 5766 | return \count($matches); |
||
| 5767 | } |
||
| 5768 | |||
| 5769 | /** |
||
| 5770 | * Removes an prefix ($needle) from start of the string ($haystack), case insensitive. |
||
| 5771 | * |
||
| 5772 | * @param string $haystack <p>The string to search in.</p> |
||
| 5773 | * @param string $needle <p>The substring to search for.</p> |
||
| 5774 | * |
||
| 5775 | * @return string <p>Return the sub-string.</p> |
||
| 5776 | */ |
||
| 5777 | 1 | View Code Duplication | public static function substr_ileft(string $haystack, string $needle): string |
| 5797 | |||
| 5798 | /** |
||
| 5799 | * Removes an suffix ($needle) from end of the string ($haystack), case insensitive. |
||
| 5800 | * |
||
| 5801 | * @param string $haystack <p>The string to search in.</p> |
||
| 5802 | * @param string $needle <p>The substring to search for.</p> |
||
| 5803 | * |
||
| 5804 | * @return string <p>Return the sub-string.</p> |
||
| 5805 | */ |
||
| 5806 | 1 | View Code Duplication | public static function substr_iright(string $haystack, string $needle): string |
| 5826 | |||
| 5827 | /** |
||
| 5828 | * Removes an prefix ($needle) from start of the string ($haystack). |
||
| 5829 | * |
||
| 5830 | * @param string $haystack <p>The string to search in.</p> |
||
| 5831 | * @param string $needle <p>The substring to search for.</p> |
||
| 5832 | * |
||
| 5833 | * @return string <p>Return the sub-string.</p> |
||
| 5834 | */ |
||
| 5835 | 1 | View Code Duplication | public static function substr_left(string $haystack, string $needle): string |
| 5855 | |||
| 5856 | /** |
||
| 5857 | * Replace text within a portion of a string. |
||
| 5858 | * |
||
| 5859 | * source: https://gist.github.com/stemar/8287074 |
||
| 5860 | * |
||
| 5861 | * @param string|string[] $str <p>The input string or an array of stings.</p> |
||
| 5862 | * @param string|string[] $replacement <p>The replacement string or an array of stings.</p> |
||
| 5863 | * @param int|int[] $offset <p> |
||
| 5864 | * If start is positive, the replacing will begin at the start'th offset |
||
| 5865 | * into string. |
||
| 5866 | * <br><br> |
||
| 5867 | * If start is negative, the replacing will begin at the start'th character |
||
| 5868 | * from the end of string. |
||
| 5869 | * </p> |
||
| 5870 | * @param int|int[]|null $length [optional] <p>If given and is positive, it represents the length of the |
||
| 5871 | * portion of string which is to be replaced. If it is negative, it |
||
| 5872 | * represents the number of characters from the end of string at which to |
||
| 5873 | * stop replacing. If it is not given, then it will default to strlen( |
||
| 5874 | * string ); i.e. end the replacing at the end of string. Of course, if |
||
| 5875 | * length is zero then this function will have the effect of inserting |
||
| 5876 | * replacement into string at the given start offset.</p> |
||
| 5877 | * |
||
| 5878 | * @return string|string[] <p>The result string is returned. If string is an array then array is returned.</p> |
||
| 5879 | */ |
||
| 5880 | 7 | public static function substr_replace($str, $replacement, $offset, $length = null) |
|
| 5957 | |||
| 5958 | /** |
||
| 5959 | * Removes an suffix ($needle) from end of the string ($haystack). |
||
| 5960 | * |
||
| 5961 | * @param string $haystack <p>The string to search in.</p> |
||
| 5962 | * @param string $needle <p>The substring to search for.</p> |
||
| 5963 | * |
||
| 5964 | * @return string <p>Return the sub-string.</p> |
||
| 5965 | */ |
||
| 5966 | 1 | View Code Duplication | public static function substr_right(string $haystack, string $needle): string |
| 5986 | |||
| 5987 | /** |
||
| 5988 | * Returns a case swapped version of the string. |
||
| 5989 | * |
||
| 5990 | * @param string $str <p>The input string.</p> |
||
| 5991 | * @param string $encoding [optional] <p>Default is UTF-8</p> |
||
| 5992 | * @param bool $cleanUtf8 [optional] <p>Remove non UTF-8 chars from the string.</p> |
||
| 5993 | * |
||
| 5994 | * @return string <p>Each character's case swapped.</p> |
||
| 5995 | */ |
||
| 5996 | 1 | public static function swapCase(string $str, string $encoding = 'UTF-8', bool $cleanUtf8 = false): string |
|
| 6028 | |||
| 6029 | /** |
||
| 6030 | * alias for "UTF8::to_ascii()" |
||
| 6031 | * |
||
| 6032 | * @see UTF8::to_ascii() |
||
| 6033 | * |
||
| 6034 | * @param string $str |
||
| 6035 | * @param string $subst_chr |
||
| 6036 | * @param bool $strict |
||
| 6037 | * |
||
| 6038 | * @return string |
||
| 6039 | * |
||
| 6040 | * @deprecated <p>use "UTF8::to_ascii()"</p> |
||
| 6041 | */ |
||
| 6042 | 7 | public static function toAscii(string $str, string $subst_chr = '?', bool $strict = false): string |
|
| 6046 | |||
| 6047 | /** |
||
| 6048 | * alias for "UTF8::to_iso8859()" |
||
| 6049 | * |
||
| 6050 | * @see UTF8::to_iso8859() |
||
| 6051 | * |
||
| 6052 | * @param string|string[] $str |
||
| 6053 | * |
||
| 6054 | * @return string|string[] |
||
| 6055 | * |
||
| 6056 | * @deprecated <p>use "UTF8::to_iso8859()"</p> |
||
| 6057 | */ |
||
| 6058 | 1 | public static function toIso8859($str) |
|
| 6062 | |||
| 6063 | /** |
||
| 6064 | * alias for "UTF8::to_latin1()" |
||
| 6065 | * |
||
| 6066 | * @see UTF8::to_latin1() |
||
| 6067 | * |
||
| 6068 | * @param string|string[] $str |
||
| 6069 | * |
||
| 6070 | * @return string|string[] |
||
| 6071 | * |
||
| 6072 | * @deprecated <p>use "UTF8::to_latin1()"</p> |
||
| 6073 | */ |
||
| 6074 | 1 | public static function toLatin1($str) |
|
| 6078 | |||
| 6079 | /** |
||
| 6080 | * alias for "UTF8::to_utf8()" |
||
| 6081 | * |
||
| 6082 | * @see UTF8::to_utf8() |
||
| 6083 | * |
||
| 6084 | * @param string|string[] $str |
||
| 6085 | * |
||
| 6086 | * @return string|string[] |
||
| 6087 | * |
||
| 6088 | * @deprecated <p>use "UTF8::to_utf8()"</p> |
||
| 6089 | */ |
||
| 6090 | 1 | public static function toUTF8($str) |
|
| 6094 | |||
| 6095 | /** |
||
| 6096 | * Convert a string into ASCII. |
||
| 6097 | * |
||
| 6098 | * @param string $str <p>The input string.</p> |
||
| 6099 | * @param string $unknown [optional] <p>Character use if character unknown. (default is ?)</p> |
||
| 6100 | * @param bool $strict [optional] <p>Use "transliterator_transliterate()" from PHP-Intl | WARNING: bad |
||
| 6101 | * performance</p> |
||
| 6102 | * |
||
| 6103 | * @return string |
||
| 6104 | */ |
||
| 6105 | 21 | public static function to_ascii(string $str, string $unknown = '?', bool $strict = false): string |
|
| 6252 | |||
| 6253 | /** |
||
| 6254 | * Convert a string into "ISO-8859"-encoding (Latin-1). |
||
| 6255 | * |
||
| 6256 | * @param string|string[] $str |
||
| 6257 | * |
||
| 6258 | * @return string|string[] |
||
| 6259 | */ |
||
| 6260 | 3 | public static function to_iso8859($str) |
|
| 6277 | |||
| 6278 | /** |
||
| 6279 | * alias for "UTF8::to_iso8859()" |
||
| 6280 | * |
||
| 6281 | * @see UTF8::to_iso8859() |
||
| 6282 | * |
||
| 6283 | * @param string|string[] $str |
||
| 6284 | * |
||
| 6285 | * @return string|string[] |
||
| 6286 | */ |
||
| 6287 | 1 | public static function to_latin1($str) |
|
| 6291 | |||
| 6292 | /** |
||
| 6293 | * This function leaves UTF-8 characters alone, while converting almost all non-UTF8 to UTF8. |
||
| 6294 | * |
||
| 6295 | * <ul> |
||
| 6296 | * <li>It decode UTF-8 codepoints and unicode escape sequences.</li> |
||
| 6297 | * <li>It assumes that the encoding of the original string is either WINDOWS-1252 or ISO-8859.</li> |
||
| 6298 | * <li>WARNING: It does not remove invalid UTF-8 characters, so you maybe need to use "UTF8::clean()" for this |
||
| 6299 | * case.</li> |
||
| 6300 | * </ul> |
||
| 6301 | * |
||
| 6302 | * @param string|string[] $str <p>Any string or array.</p> |
||
| 6303 | * @param bool $decodeHtmlEntityToUtf8 <p>Set to true, if you need to decode html-entities.</p> |
||
| 6304 | * |
||
| 6305 | * @return string|string[] <p>The UTF-8 encoded string.</p> |
||
| 6306 | */ |
||
| 6307 | 20 | public static function to_utf8($str, bool $decodeHtmlEntityToUtf8 = false) |
|
| 6400 | |||
| 6401 | /** |
||
| 6402 | * @param int $int |
||
| 6403 | * |
||
| 6404 | * @return string |
||
| 6405 | */ |
||
| 6406 | 14 | private static function to_utf8_convert($int): string |
|
| 6434 | |||
| 6435 | /** |
||
| 6436 | * Strip whitespace or other characters from beginning or end of a UTF-8 string. |
||
| 6437 | * |
||
| 6438 | * INFO: This is slower then "trim()" |
||
| 6439 | * |
||
| 6440 | * We can only use the original-function, if we use <= 7-Bit in the string / chars |
||
| 6441 | * but the check for ACSII (7-Bit) cost more time, then we can safe here. |
||
| 6442 | * |
||
| 6443 | * @param string $str <p>The string to be trimmed</p> |
||
| 6444 | * @param mixed $chars [optional] <p>Optional characters to be stripped</p> |
||
| 6445 | * |
||
| 6446 | * @return string <p>The trimmed string.</p> |
||
| 6447 | */ |
||
| 6448 | 26 | public static function trim(string $str = '', $chars = INF): string |
|
| 6461 | |||
| 6462 | /** |
||
| 6463 | * Makes string's first char uppercase. |
||
| 6464 | * |
||
| 6465 | * @param string $str <p>The input string.</p> |
||
| 6466 | * @param string $encoding [optional] <p>Set the charset.</p> |
||
| 6467 | * @param bool $cleanUtf8 [optional] <p>Remove non UTF-8 chars from the string.</p> |
||
| 6468 | * |
||
| 6469 | * @return string <p>The resulting string</p> |
||
| 6470 | */ |
||
| 6471 | 14 | public static function ucfirst(string $str, string $encoding = 'UTF-8', bool $cleanUtf8 = false): string |
|
| 6492 | |||
| 6493 | /** |
||
| 6494 | * alias for "UTF8::ucfirst()" |
||
| 6495 | * |
||
| 6496 | * @see UTF8::ucfirst() |
||
| 6497 | * |
||
| 6498 | * @param string $word |
||
| 6499 | * @param string $encoding |
||
| 6500 | * @param bool $cleanUtf8 |
||
| 6501 | * |
||
| 6502 | * @return string |
||
| 6503 | */ |
||
| 6504 | 1 | public static function ucword(string $word, string $encoding = 'UTF-8', bool $cleanUtf8 = false): string |
|
| 6508 | |||
| 6509 | /** |
||
| 6510 | * Uppercase for all words in the string. |
||
| 6511 | * |
||
| 6512 | * @param string $str <p>The input string.</p> |
||
| 6513 | * @param string[] $exceptions [optional] <p>Exclusion for some words.</p> |
||
| 6514 | * @param string $charlist [optional] <p>Additional chars that contains to words and do not start a new word.</p> |
||
| 6515 | * @param string $encoding [optional] <p>Set the charset.</p> |
||
| 6516 | * @param bool $cleanUtf8 [optional] <p>Remove non UTF-8 chars from the string.</p> |
||
| 6517 | * |
||
| 6518 | * @return string |
||
| 6519 | */ |
||
| 6520 | 8 | public static function ucwords(string $str, array $exceptions = [], string $charlist = '', string $encoding = 'UTF-8', bool $cleanUtf8 = false): string |
|
| 6577 | |||
| 6578 | /** |
||
| 6579 | * Multi decode html entity & fix urlencoded-win1252-chars. |
||
| 6580 | * |
||
| 6581 | * e.g: |
||
| 6582 | * 'test+test' => 'test test' |
||
| 6583 | * 'Düsseldorf' => 'Düsseldorf' |
||
| 6584 | * 'D%FCsseldorf' => 'Düsseldorf' |
||
| 6585 | * 'Düsseldorf' => 'Düsseldorf' |
||
| 6586 | * 'D%26%23xFC%3Bsseldorf' => 'Düsseldorf' |
||
| 6587 | * 'Düsseldorf' => 'Düsseldorf' |
||
| 6588 | * 'D%C3%BCsseldorf' => 'Düsseldorf' |
||
| 6589 | * 'D%C3%83%C2%BCsseldorf' => 'Düsseldorf' |
||
| 6590 | * 'D%25C3%2583%25C2%25BCsseldorf' => 'Düsseldorf' |
||
| 6591 | * |
||
| 6592 | * @param string $str <p>The input string.</p> |
||
| 6593 | * @param bool $multi_decode <p>Decode as often as possible.</p> |
||
| 6594 | * |
||
| 6595 | * @return string |
||
| 6596 | */ |
||
| 6597 | 1 | View Code Duplication | public static function urldecode(string $str, bool $multi_decode = true): string |
| 6626 | |||
| 6627 | /** |
||
| 6628 | * Return a array with "urlencoded"-win1252 -> UTF-8 |
||
| 6629 | * |
||
| 6630 | * @deprecated <p>use the "UTF8::urldecode()" function to decode a string</p> |
||
| 6631 | * |
||
| 6632 | * @return array |
||
| 6633 | */ |
||
| 6634 | 1 | public static function urldecode_fix_win1252_chars(): array |
|
| 6863 | |||
| 6864 | /** |
||
| 6865 | * Decodes an UTF-8 string to ISO-8859-1. |
||
| 6866 | * |
||
| 6867 | * @param string $str <p>The input string.</p> |
||
| 6868 | * @param bool $keepUtf8Chars |
||
| 6869 | * |
||
| 6870 | * @return string |
||
| 6871 | */ |
||
| 6872 | 6 | public static function utf8_decode(string $str, bool $keepUtf8Chars = false): string |
|
| 6945 | |||
| 6946 | /** |
||
| 6947 | * Encodes an ISO-8859-1 string to UTF-8. |
||
| 6948 | * |
||
| 6949 | * @param string $str <p>The input string.</p> |
||
| 6950 | * |
||
| 6951 | * @return string |
||
| 6952 | */ |
||
| 6953 | 7 | public static function utf8_encode(string $str): string |
|
| 6986 | |||
| 6987 | /** |
||
| 6988 | * fix -> utf8-win1252 chars |
||
| 6989 | * |
||
| 6990 | * @param string $str <p>The input string.</p> |
||
| 6991 | * |
||
| 6992 | * @return string |
||
| 6993 | * |
||
| 6994 | * @deprecated <p>use "UTF8::fix_simple_utf8()"</p> |
||
| 6995 | */ |
||
| 6996 | 1 | public static function utf8_fix_win1252_chars(string $str): string |
|
| 7000 | |||
| 7001 | /** |
||
| 7002 | * Returns an array with all utf8 whitespace characters. |
||
| 7003 | * |
||
| 7004 | * @see : http://www.bogofilter.org/pipermail/bogofilter/2003-March/001889.html |
||
| 7005 | * |
||
| 7006 | * @author: Derek E. [email protected] |
||
| 7007 | * |
||
| 7008 | * @return array <p> |
||
| 7009 | * An array with all known whitespace characters as values and the type of whitespace as keys |
||
| 7010 | * as defined in above URL. |
||
| 7011 | * </p> |
||
| 7012 | */ |
||
| 7013 | 1 | public static function whitespace_table(): array |
|
| 7017 | |||
| 7018 | /** |
||
| 7019 | * Limit the number of words in a string. |
||
| 7020 | * |
||
| 7021 | * @param string $str <p>The input string.</p> |
||
| 7022 | * @param int $limit <p>The limit of words as integer.</p> |
||
| 7023 | * @param string $strAddOn <p>Replacement for the striped string.</p> |
||
| 7024 | * |
||
| 7025 | * @return string |
||
| 7026 | */ |
||
| 7027 | 1 | public static function words_limit(string $str, int $limit = 100, string $strAddOn = '…'): string |
|
| 7049 | |||
| 7050 | /** |
||
| 7051 | * Wraps a string to a given number of characters |
||
| 7052 | * |
||
| 7053 | * @link http://php.net/manual/en/function.wordwrap.php |
||
| 7054 | * |
||
| 7055 | * @param string $str <p>The input string.</p> |
||
| 7056 | * @param int $width [optional] <p>The column width.</p> |
||
| 7057 | * @param string $break [optional] <p>The line is broken using the optional break parameter.</p> |
||
| 7058 | * @param bool $cut [optional] <p> |
||
| 7059 | * If the cut is set to true, the string is |
||
| 7060 | * always wrapped at or before the specified width. So if you have |
||
| 7061 | * a word that is larger than the given width, it is broken apart. |
||
| 7062 | * </p> |
||
| 7063 | * |
||
| 7064 | * @return string <p>The given string wrapped at the specified column.</p> |
||
| 7065 | */ |
||
| 7066 | 10 | public static function wordwrap(string $str, int $width = 75, string $break = "\n", bool $cut = false): string |
|
| 7114 | |||
| 7115 | /** |
||
| 7116 | * Returns an array of Unicode White Space characters. |
||
| 7117 | * |
||
| 7118 | * @return array <p>An array with numeric code point as key and White Space Character as value.</p> |
||
| 7119 | */ |
||
| 7120 | 1 | public static function ws(): array |
|
| 7124 | |||
| 7125 | } |
||
| 7126 |
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.