CakeFest 2024: The Official CakePHP Conference

mb_chr

(PHP 7 >= 7.2.0, PHP 8)

mb_chrReturn character by Unicode code point value

Descripción

mb_chr(int $codepoint, ?string $encoding = null): string|false

Returns a string containing the character specified by the Unicode code point value, encoded in the specified encoding.

This function complements mb_ord().

Parámetros

codepoint

A Unicode codepoint value, e.g. 128024 for U+1F418 ELEPHANT

encoding

El parámetro encoding es la codificación de caracteres. Si es omitido, será usado el valor de la codificación de caracteres interna.

Valores devueltos

A string containing the requested character, if it can be represented in the specified encoding o false en caso de error.

Historial de cambios

Versión Descripción
8.0.0 encoding is nullable now.

Ejemplos

Ejemplo #1 Probar diferentes puntos de código

<?php
$values
= [65, 63, 0x20AC, 128024];
foreach (
$values as $value) {
var_dump(mb_chr($value, 'UTF-8'));
var_dump(mb_chr($value, 'ISO-8859-1'));
}
?>

El resultado del ejemplo sería:

string(1) "A"
string(1) "A"
string(1) "?"
string(1) "?"
string(3) "€"
bool(false)
string(4) "🐘"
bool(false)

Ver también

  • mb_internal_encoding() - Establece/obtiene la codificación de caracteres interna
  • mb_ord() - Get Unicode code point of character
  • IntlChar::ord() - Devolver el valor del punto de código de Unicode de un carácter
  • chr() - Devuelve un caracter específico

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top