mirror of
https://github.com/php/doc-es.git
synced 2026-03-26 00:12:06 +01:00
git-svn-id: https://svn.php.net/repository/phpdoc/es/trunk@338215 c90b9560-bf6c-de11-be94-00142212c4b1
293 lines
7.3 KiB
XML
293 lines
7.3 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
<!-- EN-Revision: 3dc8d0599b6e3022f3ed2e9c42155739bf45810c Maintainer: seros Status: ready -->
|
|
<!-- Reviewed: no -->
|
|
<refentry xmlns="http://docbook.org/ns/docbook" xml:id="function.getopt">
|
|
<refnamediv>
|
|
<refname>getopt</refname>
|
|
<refpurpose>Obtiene las opciones de la lista de argumentos de la línea de comandos</refpurpose>
|
|
</refnamediv>
|
|
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis>
|
|
<type>array</type><methodname>getopt</methodname>
|
|
<methodparam><type>string</type><parameter>options</parameter></methodparam>
|
|
<methodparam choice="opt"><type>array</type><parameter>longopts</parameter></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
Analiza las opciones pasadas al script.
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>options</parameter></term>
|
|
<listitem>
|
|
<simpara>
|
|
Cada carácter de esta cadena de texto se usará como un carácter de opción
|
|
y se comparará con aquellas opciones pasadas al script que comiencen con un
|
|
guión simple (<literal>-</literal>).
|
|
</simpara>
|
|
<simpara>
|
|
Por ejemplo, el string de opciones <literal>"x"</literal> reconocerá
|
|
la opción <literal>-x</literal>.
|
|
</simpara>
|
|
<simpara>
|
|
Sólo se permiten a-z, A-Z y 0-9.
|
|
</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>longopts</parameter></term>
|
|
<listitem>
|
|
<simpara>
|
|
Matriz de opciones. Cada elemento de este array se usará como texto de opciones
|
|
y se compararán con aquellas opciones pasadas al script que comiencen con
|
|
dos guiones (<literal>--</literal>).
|
|
</simpara>
|
|
<simpara>
|
|
Por ejemplo, longopts tuviera un elemento con <literal>"opt"</literal>, reconocería la
|
|
opción <literal>--opt</literal>.
|
|
</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
<para>
|
|
El parámetro <parameter>options</parameter> puede contener los siguientes
|
|
elementos:
|
|
<simplelist>
|
|
<member>Caracteres individuales (no acepta valores)</member>
|
|
<member>Caracteres seguidos por dos puntos (el parámetro exije un valor)</member>
|
|
<member>Caracteres seguidos dos veces por dos puntos (valor opcional)</member>
|
|
</simplelist>
|
|
Los valores de opción serán el primer argumento tras el string. Si se requiere un valor,
|
|
no importa si este tiene espacios en blanco delante o no. Véase la nota.
|
|
<note>
|
|
<simpara>
|
|
Los valores opcionales no aceptan un <literal>" "</literal> (espacio) como separador.
|
|
</simpara>
|
|
</note>
|
|
</para>
|
|
<note>
|
|
<para>
|
|
El formato de <parameter>options</parameter> y de
|
|
<parameter>longopts</parameter> es casi igual. La única diferencia es que
|
|
<parameter>longopts</parameter> contiene un array de opciones (donde cada elemento
|
|
es la opción) mientras que <parameter>options</parameter> contiene un string
|
|
(donde cada carácter es la opción).
|
|
</para>
|
|
</note>
|
|
</refsect1>
|
|
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
Esta función devolverá un array de parejas opciones / argumentos, &return.falseforfailure;.
|
|
</para>
|
|
<note>
|
|
<para>
|
|
El análisis de opciones finalizará cuando se encuentre alguna no-opción. Todo lo que haya
|
|
a continuación será descartado.
|
|
</para>
|
|
</note>
|
|
</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.3.0</entry>
|
|
<entry>
|
|
Añadido soporte para usar "=" como separador de argumento/valor.
|
|
</entry>
|
|
</row>
|
|
<row>
|
|
<entry>5.3.0</entry>
|
|
<entry>
|
|
Añadido soporte para valores opcionales (especificado mediante "::").
|
|
</entry>
|
|
</row>
|
|
<row>
|
|
<entry>5.3.0</entry>
|
|
<entry>
|
|
El parámetro <parameter>longopts</parameter> está disponible en todos los sistemas.
|
|
</entry>
|
|
</row>
|
|
<row>
|
|
<entry>5.3.0</entry>
|
|
<entry>
|
|
Esta función ya no depende del sistema y funciona también en Windows.
|
|
</entry>
|
|
</row>
|
|
</tbody>
|
|
</tgroup>
|
|
</informaltable>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example xml:id="getopt.examples-1">
|
|
<title>Ejemplo de <function>getopt</function>: Lo básico</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
// Script example.php
|
|
$options = getopt("f:hp:");
|
|
var_dump($options);
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
<programlisting role="shell">
|
|
<![CDATA[
|
|
shell> php example.php -fvalue -h
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs;
|
|
<screen>
|
|
<![CDATA[
|
|
array(2) {
|
|
["f"]=>
|
|
string(5) "value"
|
|
["h"]=>
|
|
bool(false)
|
|
}
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
<example xml:id="getopt.examples-2">
|
|
<title>Ejemplo de <function>getopt</function>: Introducir opciones long</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
// Script example.php
|
|
$shortopts = "";
|
|
$shortopts .= "f:"; // Valor obligatorio
|
|
$shortopts .= "v::"; // Valor opcional
|
|
$shortopts .= "abc"; // Estas opciones no aceptan valores
|
|
|
|
$longopts = array(
|
|
"required:", // Valor obligatorio
|
|
"optional::", // Valor opcional
|
|
"option", // Sin valores
|
|
"opt", // Sin valores
|
|
);
|
|
$options = getopt($shortopts, $longopts);
|
|
var_dump($options);
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
<programlisting role="shell">
|
|
<![CDATA[
|
|
shell> php example.php -f "value for f" -v -a --required value --optional="optional value" --option
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs;
|
|
<screen>
|
|
<![CDATA[
|
|
array(6) {
|
|
["f"]=>
|
|
string(11) "value for f"
|
|
["v"]=>
|
|
bool(false)
|
|
["a"]=>
|
|
bool(false)
|
|
["required"]=>
|
|
string(5) "value"
|
|
["optional"]=>
|
|
string(14) "optional value"
|
|
["option"]=>
|
|
bool(false)
|
|
}
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
<example xml:id="getopt.examples-3">
|
|
<title>Ejemplo de <function>getopt</function>: Pasar varias opciones como una</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
// Script example.php
|
|
$options = getopt("abc");
|
|
var_dump($options);
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
<programlisting role="shell">
|
|
<![CDATA[
|
|
shell> php example.php -aaac
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs;
|
|
<screen>
|
|
<![CDATA[
|
|
array(2) {
|
|
["a"]=>
|
|
array(3) {
|
|
[0]=>
|
|
bool(false)
|
|
[1]=>
|
|
bool(false)
|
|
[2]=>
|
|
bool(false)
|
|
}
|
|
["c"]=>
|
|
bool(false)
|
|
}
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="seealso">
|
|
&reftitle.seealso;
|
|
<para>
|
|
<simplelist>
|
|
<member><link linkend="reserved.variables.argv"><varname>$argv</varname></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
|
|
-->
|