mirror of
https://github.com/php/doc-es.git
synced 2026-04-25 16:18:09 +02:00
9f7804a633
* feat(translation): update revision EN * feat(translation): update revision EN
187 lines
4.8 KiB
XML
187 lines
4.8 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- EN-Revision: 45042fef652f1b4e904e809fcbfcf31f6c60670b Maintainer: PhilDaiguille Status: ready -->
|
|
<!-- Reviewed: no -->
|
|
<refentry xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://docbook.org/ns/docbook" xml:id="function.chr">
|
|
<refnamediv>
|
|
<refname>chr</refname>
|
|
<refpurpose>Generar un string de un byte a partir de un número</refpurpose>
|
|
</refnamediv>
|
|
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis>
|
|
<type>string</type><methodname>chr</methodname>
|
|
<methodparam><type>int</type><parameter>codepoint</parameter></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
Devuelve un &string; de un solo carácter que contiene el carácter especificado al
|
|
interpretar <parameter>codepoint</parameter> como un &integer; sin signo.
|
|
</para>
|
|
<para>
|
|
Esto puede ser utilizado para crear un &string; de un solo carácter en una
|
|
codificación de un byte como ASCII, ISO-8859 o Windows 1252, pasando la
|
|
posición del carácter deseado en la tabla de correspondencia de la codificación.
|
|
Sin embargo, es importante tener en cuenta que esta función no es consciente de ninguna codificación
|
|
de &string;, y en particular no puede ser transmitido un valor de punto de código Unicode para generar un &string; en una codificación multibyte como UTF-8
|
|
o UTF-16.
|
|
</para>
|
|
<para>
|
|
Esta función complementa <function>ord</function>.
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>codepoint</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Un &integer; entre 0 y 255;
|
|
</para>
|
|
<para>
|
|
Los valores fuera del rango válido (0..255) serán
|
|
convertidos a valor positivo, y terminarán en 255, lo que es
|
|
equivalente al siguiente algoritmo:
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
while ($bytevalue < 0) {
|
|
$bytevalue += 256;
|
|
}
|
|
$bytevalue %= 256;
|
|
]]>
|
|
</programlisting>
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
Devuelve un &string; de un solo carácter que contiene el byte especificado.
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="changelog">
|
|
&reftitle.changelog;
|
|
<informaltable>
|
|
<tgroup cols="2">
|
|
<thead>
|
|
<row>
|
|
<entry>&Version;</entry>
|
|
<entry>&Description;</entry>
|
|
</row>
|
|
</thead>
|
|
<tbody>
|
|
<row>
|
|
<entry>7.4.0</entry>
|
|
<entry>
|
|
Esta función ya no acepta silenciosamente los <parameter>codepoint</parameter>s
|
|
no soportados, y convierte estos valores a <literal>0</literal>.
|
|
</entry>
|
|
</row>
|
|
</tbody>
|
|
</tgroup>
|
|
</informaltable>
|
|
</refsect1>
|
|
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title>Ejemplo con <function>chr</function></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
// Supone que el string será utilizado como ASCII o una codificación
|
|
// compatible con este
|
|
|
|
$str = "The string ends in escape: ";
|
|
|
|
// Añade un carácter de escape al final del string $str
|
|
$str .= chr(27);
|
|
echo $str, PHP_EOL;
|
|
// Esto es a menudo más práctico, y realiza lo mismo
|
|
|
|
$str = sprintf("The string ends in escape: %c", 27);
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title>Comportamiento de desbordamiento</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
echo chr(-159), chr(833), PHP_EOL;
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs;
|
|
<screen>
|
|
<![CDATA[
|
|
aA
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title>Construir un string UTF-8 a partir de bytes individuales</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$str = chr(240) . chr(159) . chr(144) . chr(152);
|
|
echo $str, PHP_EOL;
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs;
|
|
<screen>
|
|
🐘
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="seealso">
|
|
&reftitle.seealso;
|
|
<para>
|
|
<simplelist>
|
|
<member><function>sprintf</function> con el carácter de formato <literal>%c</literal></member>
|
|
<member><function>ord</function></member>
|
|
<member><link xlink:href="&url.asciitable;">Tabla ASCII</link></member>
|
|
<member><function>mb_chr</function></member>
|
|
<member><function>IntlChar::chr</function></member>
|
|
</simplelist>
|
|
</para>
|
|
</refsect1>
|
|
|
|
</refentry>
|
|
<!-- Keep this comment at the end of the file
|
|
Local variables:
|
|
mode: sgml
|
|
sgml-omittag:t
|
|
sgml-shorttag:t
|
|
sgml-minimize-attributes:nil
|
|
sgml-always-quote-attributes:t
|
|
sgml-indent-step:1
|
|
sgml-indent-data:t
|
|
indent-tabs-mode:nil
|
|
sgml-parent-document:nil
|
|
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
|
sgml-exposed-tags:nil
|
|
sgml-local-catalogs:nil
|
|
sgml-local-ecat-files:nil
|
|
End:
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
vim: et tw=78 syn=sgml
|
|
vi: ts=1 sw=1
|
|
-->
|