IntlChar::tolower

(PHP 7, PHP 8)

IntlChar::tolowerConvierte un carácter Unicode a minúscula

Descripción

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

El carácter dado se mapea a su equivalente en minúscula. Si el carácter no tiene equivalente en minúscula, se devuelve el carácter original.

Parámetros

codepoint

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

Valores devueltos

Devuelve el Simple_Lowercase_Mapping del punto de código, si está disponible; de lo contrario, el punto de código mismo. Devuelve null en caso de error.

El tipo de retorno es int a menos que el punto de código haya sido pasado como un string UTF-8, en cuyo caso se devuelve un string. Devuelve null en caso de fallo.

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 ejemplo anterior mostrará:

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
5 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