PHP 8.3.4 Released!

IntlChar::tolower

(PHP 7, PHP 8)

IntlChar::tolowerTransforma o caractere Unicode em minúscula

Descrição

public static IntlChar::tolower(int|string $codepoint): int|string|null

O caractere é mapeado para a sua letra minúscula equivalente. Se o caractere não tiver minúscula equivalente, o caractere original em si é retornado.

Parâmetros

codepoint

O valor int do ponto de código (por exemplo, 0x2603 para U+2603 SNOWMAN) ou o caractere codificado como uma string UTF-8 (por exemplo, "\u{2603}").

Valor Retornado

Retorna o mapeamento do tipo Simple_Lowercase_Mapping do ponto de código, se houver; caso contrário, o próprio ponto de código. Retorna null em caso de falha.

O tipo do retorno é int, a menos que o ponto de código tenha sido passado como uma string UTF-8, caso em que uma string é retornada. Retorna null em caso de falha.

Exemplos

Exemplo #1 Testando diferentes pontos de código

<?php
var_dump
(IntlChar::tolower("A"));
var_dump(IntlChar::tolower("a"));
var_dump(IntlChar::tolower("Φ"));
var_dump(IntlChar::tolower("φ"));
var_dump(IntlChar::tolower("1"));
var_dump(IntlChar::tolower(ord("A")));
var_dump(IntlChar::tolower(ord("a")));
?>

O exemplo acima produzirá:

string(1) "a"
string(1) "a"
string(2) "φ"
string(2) "φ"
string(1) "1"
int(97)
int(97)

Veja Também

add a note

User Contributed Notes 1 note

up
0
Patanjali
3 years ago
The other function I wrote to replace mb_strtolower may not work properly, as it erroneously equated graphemes with codepoints.

tolower, like many IntlChar methods, works specifically on codepoints, so requires a codepoint iterator to isolate each.

Also, because in tolower, if there is no lowercase version of the codepoint, the supplied one is returned, so there is no need to specially test for alphabetic codepoints before conversion.

<?php
function u_tolower($text=''){
// if blank, return blank (don't waste CPU cycles)
if($text==''){return'';}

// create the codepoint break iterator to identify the start of each codepoint
$iterator=IntlBreakIterator::createCodePointInstance();

// load the text
$iterator->setText($text);

// using a parts iterator to extract each codepoint itself, convert and append it to the new string
$newtext='';
foreach(
$iterator->getPartsIterator() as $codepoint){$newtext.=IntlChar::tolower($codepoint);}

// return converted text
return $newtext;
}
?>
To Top