mirror of
https://github.com/php/doc-es.git
synced 2026-03-25 16:02:13 +01:00
git-svn-id: https://svn.php.net/repository/phpdoc/es/trunk@338157 c90b9560-bf6c-de11-be94-00142212c4b1
300 lines
8.1 KiB
XML
300 lines
8.1 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
<!-- EN-Revision: 1b7d2330d76d31002825ee20b70417d892458204 Maintainer: seros Status: ready -->
|
|
<!-- Reviewed: no -->
|
|
<refentry xml:id="function.parse-url" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
<refnamediv>
|
|
<refname>parse_url</refname>
|
|
<refpurpose>Analiza un URL y devuelve sus componentes</refpurpose>
|
|
</refnamediv>
|
|
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis>
|
|
<type>mixed</type><methodname>parse_url</methodname>
|
|
<methodparam><type>string</type><parameter>url</parameter></methodparam>
|
|
<methodparam choice="opt"><type>int</type><parameter>component</parameter><initializer>-1</initializer></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
Esta función analiza una URL y devuelve un array asociativo que
|
|
contiene aquellos componentes presentes en la URL.
|
|
</para>
|
|
<para>
|
|
El propósito de esta función <emphasis role="strong">no</emphasis> es validar
|
|
la URL dada, tan solo la separa en las partes listadas anteriormente. Las URLs parciales
|
|
son aceptadas también, <function>parse_url</function> hace lo mejor que puede para procesarlas
|
|
correctamente.
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>url</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
La URL a analizar. Caracteres inválidos son reemplazados por
|
|
<literal>_</literal>.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>component</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Especifique uno de <constant>PHP_URL_SCHEME</constant>,
|
|
<constant>PHP_URL_HOST</constant>, <constant>PHP_URL_PORT</constant>,
|
|
<constant>PHP_URL_USER</constant>, <constant>PHP_URL_PASS</constant>,
|
|
<constant>PHP_URL_PATH</constant>, <constant>PHP_URL_QUERY</constant>
|
|
o <constant>PHP_URL_FRAGMENT</constant> para recibir solo un
|
|
componente URL específico como un valor tipo <type>string</type> (excepto cuando
|
|
se da <constant>PHP_URL_PORT</constant>, en cuyo caso el valor de
|
|
retorno será un <type>integer</type>).
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
Sobre URLs seriamente malformadas, <function>parse_url</function> puede devolver
|
|
&false;.
|
|
</para>
|
|
<para>
|
|
Si se omite el parámetro <parameter>component</parameter>, un
|
|
<type>array</type> asociativo es devuelto. Al menos un elemento estará
|
|
presente en el array. Claves potenciales en este array son:
|
|
<itemizedlist>
|
|
<listitem>
|
|
<simpara>
|
|
<varname remap="structfield">scheme</varname> - p.ej. http
|
|
</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara>
|
|
<varname remap="structfield">host</varname>
|
|
</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara>
|
|
<varname remap="structfield">port</varname>
|
|
</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara>
|
|
<varname remap="structfield">user</varname>
|
|
</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara>
|
|
<varname remap="structfield">pass</varname>
|
|
</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara>
|
|
<varname remap="structfield">path</varname>
|
|
</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara>
|
|
<varname remap="structfield">query</varname> - después del signo <literal>?</literal>
|
|
</simpara>
|
|
</listitem>
|
|
<listitem>
|
|
<simpara>
|
|
<varname remap="structfield">fragment</varname> - después del signo <literal>#</literal>
|
|
</simpara>
|
|
</listitem>
|
|
</itemizedlist>
|
|
</para>
|
|
<para>
|
|
Si se especifica el parámetro <parameter>componente</parameter>,
|
|
<function>parse_url</function> devolverá un <type>string</type> (o un
|
|
<type>integer</type>, para el caso de <constant>PHP_URL_PORT</constant>)
|
|
en lugar de un <type>array</type>. Si el componente solicitado no existe en la
|
|
URL dada, será devuelto &null;.
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="changelog">
|
|
&reftitle.changelog;
|
|
<para>
|
|
<informaltable>
|
|
<tgroup cols="2">
|
|
<thead>
|
|
<row>
|
|
<entry>&Version;</entry>
|
|
<entry>&Description;</entry>
|
|
</row>
|
|
</thead>
|
|
<tbody>
|
|
<row>
|
|
<entry>5.4.7</entry>
|
|
<entry>
|
|
Arreglado el reconocimiento de <emphasis>host</emphasis> cuando <emphasis>scheme</emphasis>
|
|
es omitido y está presente un separador de componentes que lo encabeza.
|
|
</entry>
|
|
</row>
|
|
<row>
|
|
<entry>5.3.3</entry>
|
|
<entry>
|
|
Eliminado el <constant>E_WARNING</constant> que era producido cuando fallaba el análisis de la
|
|
URL.
|
|
</entry>
|
|
</row>
|
|
<row>
|
|
<entry>5.1.2</entry>
|
|
<entry>Se agregó el parámetro <parameter>component.</parameter></entry>
|
|
</row>
|
|
</tbody>
|
|
</tgroup>
|
|
</informaltable>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title>Un ejemplo de <function>parse_url</function></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$url = 'http://username:password@hostname:9090/path?arg=value#anchor';
|
|
|
|
var_dump(parse_url($url));
|
|
var_dump(parse_url($url, PHP_URL_SCHEME));
|
|
var_dump(parse_url($url, PHP_URL_USER));
|
|
var_dump(parse_url($url, PHP_URL_PASS));
|
|
var_dump(parse_url($url, PHP_URL_HOST));
|
|
var_dump(parse_url($url, PHP_URL_PORT));
|
|
var_dump(parse_url($url, PHP_URL_PATH));
|
|
var_dump(parse_url($url, PHP_URL_QUERY));
|
|
var_dump(parse_url($url, PHP_URL_FRAGMENT));
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs;
|
|
<screen>
|
|
<![CDATA[
|
|
array(8) {
|
|
["scheme"]=>
|
|
string(4) "http"
|
|
["host"]=>
|
|
string(8) "hostname"
|
|
["port"]=>
|
|
int(9090)
|
|
["user"]=>
|
|
string(8) "username"
|
|
["pass"]=>
|
|
string(8) "password"
|
|
["path"]=>
|
|
string(5) "/path"
|
|
["query"]=>
|
|
string(9) "arg=value"
|
|
["fragment"]=>
|
|
string(6) "anchor"
|
|
}
|
|
string(4) "http"
|
|
string(8) "username"
|
|
string(8) "password"
|
|
string(8) "hostname"
|
|
int(9090)
|
|
string(5) "/path"
|
|
string(9) "arg=value"
|
|
string(6) "anchor"
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title>Un ejemplo de <function>parse_url</function> con el esquema ausente</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$url = '//www.example.com/path?googleguy=googley';
|
|
|
|
// Antes de 5.4.7, esto mostraría la ruta como "//www.example.com/path"
|
|
var_dump(parse_url($url));
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs;
|
|
<screen>
|
|
<![CDATA[
|
|
array(3) {
|
|
["host"]=>
|
|
string(15) "www.example.com"
|
|
["path"]=>
|
|
string(5) "/path"
|
|
["query"]=>
|
|
string(17) "googleguy=googley"
|
|
}
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="notes">
|
|
&reftitle.notes;
|
|
<note>
|
|
<para>
|
|
Esta función no funciona con URLs relativas.
|
|
</para>
|
|
</note>
|
|
<note>
|
|
<para>
|
|
Esta función tiene el propósito específico de procesar URLs, y no URIs.
|
|
Sin embargo, para cumplir con los requerimientos de retrocompatibilidad
|
|
de PHP, hace una excepción para el esquema file:// en donde se permiten tres
|
|
barras (file:///...). Para cualquier otro esquema, lo anterior es inválido.
|
|
</para>
|
|
</note>
|
|
</refsect1>
|
|
|
|
<refsect1 role="seealso">
|
|
&reftitle.seealso;
|
|
<para>
|
|
<simplelist>
|
|
<member><function>pathinfo</function></member>
|
|
<member><function>parse_str</function></member>
|
|
<member><function>http_build_query</function></member>
|
|
<member><function>http_build_url</function></member>
|
|
<member><function>dirname</function></member>
|
|
<member><function>basename</function></member>
|
|
<member><link xlink:href="&url.rfc;3986">RFC 3986</link></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
|
|
-->
|