mirror of
https://github.com/php/doc-es.git
synced 2026-03-23 23:12:09 +01:00
217 lines
6.0 KiB
XML
217 lines
6.0 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- EN-Revision: 4e69a9f2b14deefca0befec576335e33152448f3 Maintainer: PhilDaiguille Status: ready -->
|
|
<!-- Reviewed: no -->
|
|
<refentry xml:id="function.mb-decode-numericentity" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
<refnamediv>
|
|
<refname>mb_decode_numericentity</refname>
|
|
<refpurpose>Decodificar referencia numérica de cadena HTML a carácter</refpurpose>
|
|
</refnamediv>
|
|
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis>
|
|
<type>string</type><methodname>mb_decode_numericentity</methodname>
|
|
<methodparam><type>string</type><parameter>string</parameter></methodparam>
|
|
<methodparam><type>array</type><parameter>map</parameter></methodparam>
|
|
<methodparam choice="opt"><type class="union"><type>string</type><type>null</type></type><parameter>encoding</parameter><initializer>&null;</initializer></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
Convierte la referencia numérica de cadena de <type>string</type>
|
|
<parameter>string</parameter> en un bloque especificado a carácter.
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>string</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
La <type>string</type> que se está decodificando.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>map</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
<parameter>map</parameter> es un <type>array</type> que especifica
|
|
el área de código a convertir.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>encoding</parameter></term>
|
|
<listitem>
|
|
&mbstring.encoding.parameter;
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
La <type>string</type> convertida.
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="errors">
|
|
&reftitle.errors;
|
|
<simpara>
|
|
Genera una excepción <exceptionname>ValueError</exceptionname> si
|
|
<parameter>map</parameter> no es una lista de &integer;s.
|
|
</simpara>
|
|
</refsect1>
|
|
|
|
<refsect1 role="changelog">
|
|
&reftitle.changelog;
|
|
<informaltable>
|
|
<tgroup cols="2">
|
|
<thead>
|
|
<row>
|
|
<entry>&Version;</entry>
|
|
<entry>&Description;</entry>
|
|
</row>
|
|
</thead>
|
|
<tbody>
|
|
<row>
|
|
<entry>8.4.0</entry>
|
|
<entry>
|
|
<function>mb_decode_numericentity</function> ahora genera una
|
|
<exceptionname>ValueError</exceptionname> si <parameter>map</parameter>
|
|
no es una lista de &integer;s.
|
|
</entry>
|
|
</row>
|
|
&mbstring.changelog.encoding-nullable;
|
|
</tbody>
|
|
</tgroup>
|
|
</informaltable>
|
|
</refsect1>
|
|
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title>Ejemplo de <parameter>map</parameter></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$convmap = array (
|
|
int start_code1, int end_code1, int offset1, int mask1,
|
|
int start_code2, int end_code2, int offset2, int mask2,
|
|
// ........
|
|
int start_codeN, int end_codeN, int offsetN, int maskN );
|
|
// Especificar valor Unicode para start_codeN y end_codeN
|
|
// Añadir offsetN al valor y realizar 'AND' a nivel de bits con maskN,
|
|
// luego convertir el valor a referencia numérica de cadena.
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
|
|
<para>
|
|
<example>
|
|
<title>Ejemplo de <parameter>map</parameter> para escapar cadena JavaScript</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
function escape_javascript_string($str) {
|
|
$map = [
|
|
1,1,1,1,1,1,1,1,1,1,
|
|
1,1,1,1,1,1,1,1,1,1,
|
|
1,1,1,1,1,1,1,1,1,1,
|
|
1,1,1,1,1,1,1,1,1,1,
|
|
1,1,1,1,1,1,1,1,0,0, // 49
|
|
0,0,0,0,0,0,0,0,1,1,
|
|
1,1,1,1,1,0,0,0,0,0,
|
|
0,0,0,0,0,0,0,0,0,0,
|
|
0,0,0,0,0,0,0,0,0,0,
|
|
0,1,1,1,1,1,1,0,0,0, // 99
|
|
0,0,0,0,0,0,0,0,0,0,
|
|
0,0,0,0,0,0,0,0,0,0,
|
|
0,0,0,1,1,1,1,1,1,1,
|
|
1,1,1,1,1,1,1,1,1,1,
|
|
1,1,1,1,1,1,1,1,1,1, // 149
|
|
1,1,1,1,1,1,1,1,1,1,
|
|
1,1,1,1,1,1,1,1,1,1,
|
|
1,1,1,1,1,1,1,1,1,1,
|
|
1,1,1,1,1,1,1,1,1,1,
|
|
1,1,1,1,1,1,1,1,1,1, // 199
|
|
1,1,1,1,1,1,1,1,1,1,
|
|
1,1,1,1,1,1,1,1,1,1,
|
|
1,1,1,1,1,1,1,1,1,1,
|
|
1,1,1,1,1,1,1,1,1,1,
|
|
1,1,1,1,1,1,1,1,1,1, // 249
|
|
1,1,1,1,1,1,1, // 255
|
|
];
|
|
// Codificación de caracteres es UTF-8
|
|
$mblen = mb_strlen($str, 'UTF-8');
|
|
$utf32 = bin2hex(mb_convert_encoding($str, 'UTF-32', 'UTF-8'));
|
|
for ($i=0, $encoded=''; $i < $mblen; $i++) {
|
|
$u = substr($utf32, $i*8, 8);
|
|
$v = base_convert($u, 16, 10);
|
|
if ($v < 256 && $map[$v]) {
|
|
$encoded .= '\\x'.substr($u, 6,2);
|
|
} else if ($v == 2028) {
|
|
$encoded .= '\\u2028';
|
|
} else if ($v == 2029) {
|
|
$encoded .= '\\u2029';
|
|
} else {
|
|
$encoded .= mb_convert_encoding(hex2bin($u), 'UTF-8', 'UTF-32');
|
|
}
|
|
}
|
|
return $encoded;
|
|
}
|
|
|
|
// Datos de prueba
|
|
$convmap = [ 0x0, 0xffff, 0, 0xffff ];
|
|
$msg = '';
|
|
for ($i=0; $i < 1000; $i++) {
|
|
// chr() no puede generar datos UTF-8 correctos mayores que 128, usar mb_decode_numericentity().
|
|
$msg .= mb_decode_numericentity('&#'.$i.';', $convmap, 'UTF-8');
|
|
}
|
|
|
|
// var_dump($msg);
|
|
var_dump(escape_javascript_string($msg));
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="seealso">
|
|
&reftitle.seealso;
|
|
<para>
|
|
<simplelist>
|
|
<member><function>mb_encode_numericentity</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
|
|
-->
|