|
@@ 5316-5355 (lines=40) @@
|
| 5313 |
|
* |
| 5314 |
|
* @return string str with all alphabetic characters converted to lowercase. |
| 5315 |
|
*/ |
| 5316 |
|
public static function strtolower($str, string $encoding = 'UTF-8', bool $cleanUtf8 = false, string $lang = null): string |
| 5317 |
|
{ |
| 5318 |
|
// init |
| 5319 |
|
$str = (string)$str; |
| 5320 |
|
if (!isset($str[0])) { |
| 5321 |
|
return ''; |
| 5322 |
|
} |
| 5323 |
|
|
| 5324 |
|
if ($cleanUtf8 === true) { |
| 5325 |
|
// "\mb_strpos" and "\iconv_strpos" returns wrong position, |
| 5326 |
|
// if invalid characters are found in $haystack before $needle |
| 5327 |
|
$str = self::clean($str); |
| 5328 |
|
} |
| 5329 |
|
|
| 5330 |
|
if ($encoding !== 'UTF-8') { |
| 5331 |
|
$encoding = self::normalize_encoding($encoding, 'UTF-8'); |
| 5332 |
|
} |
| 5333 |
|
|
| 5334 |
|
if ($lang !== null) { |
| 5335 |
|
if (!isset(self::$SUPPORT['already_checked_via_portable_utf8'])) { |
| 5336 |
|
self::checkForSupport(); |
| 5337 |
|
} |
| 5338 |
|
|
| 5339 |
|
if (self::$SUPPORT['intl'] === true) { |
| 5340 |
|
|
| 5341 |
|
$langCode = $lang . '-Lower'; |
| 5342 |
|
if (!\in_array($langCode, self::$SUPPORT['intl__transliterator_list_ids'], true)) { |
| 5343 |
|
\trigger_error('UTF8::strtolower() without intl for special language: ' . $lang, E_USER_WARNING); |
| 5344 |
|
|
| 5345 |
|
$langCode = 'Any-Lower'; |
| 5346 |
|
} |
| 5347 |
|
|
| 5348 |
|
return transliterator_transliterate($langCode, $str); |
| 5349 |
|
} |
| 5350 |
|
|
| 5351 |
|
\trigger_error('UTF8::strtolower() without intl + PHP >= 5.4 cannot handle the "lang"-parameter: ' . $lang, E_USER_WARNING); |
| 5352 |
|
} |
| 5353 |
|
|
| 5354 |
|
return \mb_strtolower($str, $encoding); |
| 5355 |
|
} |
| 5356 |
|
|
| 5357 |
|
/** |
| 5358 |
|
* Generic case sensitive transformation for collation matching. |
|
@@ 5382-5420 (lines=39) @@
|
| 5379 |
|
* |
| 5380 |
|
* @return string <p>$str with all alphabetic characters converted to uppercase.</p> |
| 5381 |
|
*/ |
| 5382 |
|
public static function strtoupper($str, string $encoding = 'UTF-8', bool $cleanUtf8 = false, string $lang = null): string |
| 5383 |
|
{ |
| 5384 |
|
$str = (string)$str; |
| 5385 |
|
if (!isset($str[0])) { |
| 5386 |
|
return ''; |
| 5387 |
|
} |
| 5388 |
|
|
| 5389 |
|
if ($cleanUtf8 === true) { |
| 5390 |
|
// "\mb_strpos" and "\iconv_strpos" returns wrong position, |
| 5391 |
|
// if invalid characters are found in $haystack before $needle |
| 5392 |
|
$str = self::clean($str); |
| 5393 |
|
} |
| 5394 |
|
|
| 5395 |
|
if ($encoding !== 'UTF-8') { |
| 5396 |
|
$encoding = self::normalize_encoding($encoding, 'UTF-8'); |
| 5397 |
|
} |
| 5398 |
|
|
| 5399 |
|
if ($lang !== null) { |
| 5400 |
|
if (!isset(self::$SUPPORT['already_checked_via_portable_utf8'])) { |
| 5401 |
|
self::checkForSupport(); |
| 5402 |
|
} |
| 5403 |
|
|
| 5404 |
|
if (self::$SUPPORT['intl'] === true) { |
| 5405 |
|
|
| 5406 |
|
$langCode = $lang . '-Upper'; |
| 5407 |
|
if (!\in_array($langCode, self::$SUPPORT['intl__transliterator_list_ids'], true)) { |
| 5408 |
|
\trigger_error('UTF8::strtoupper() without intl for special language: ' . $lang, E_USER_WARNING); |
| 5409 |
|
|
| 5410 |
|
$langCode = 'Any-Upper'; |
| 5411 |
|
} |
| 5412 |
|
|
| 5413 |
|
return transliterator_transliterate($langCode, $str); |
| 5414 |
|
} |
| 5415 |
|
|
| 5416 |
|
\trigger_error('UTF8::strtolower() without intl + PHP >= 5.4 cannot handle the "lang"-parameter: ' . $lang, E_USER_WARNING); |
| 5417 |
|
} |
| 5418 |
|
|
| 5419 |
|
return \mb_strtoupper($str, $encoding); |
| 5420 |
|
} |
| 5421 |
|
|
| 5422 |
|
/** |
| 5423 |
|
* Translate characters or replace sub-strings. |