CakeFest 2024: The Official CakePHP Conference

IntlChar::tolower

(PHP 7, PHP 8)

IntlChar::tolowerConvertir a minúsculas un carácter Unicode

Descripción

public static IntlChar::tolower(mixed $codepoint): mixed

Se hace corresponder el carácter dado con su equivalente en minúsculas. Si el carácter no tiene dicho equivalente, se devuelve el carácter en sí.

Parámetros

codepoint

El valor de tipo integer del punto de código (p.ej. 0x2603 para U+2603 SNOWMAN), o el carácter codificado como un string UTF-8 (p.ej. "\u{2603}")

Valores devueltos

Devuelve el Simple_Lowercase_Mapping del punto de código, si lo hubiera; de lo contrario devuelve el punto de código en sí.

El tipo devuelto será integer a menos que el punto de código se pase como un string UTF-8, en cuyo caso será devuelto un string.

Ejemplos

Ejemplo #1 Probar diferentes puntos 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")));
?>

El resultado del ejemplo sería:

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

Ver también

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