mirror of
https://github.com/macintoshplus/doc-fr.git
synced 2026-03-25 17:32:07 +01:00
321 lines
8.3 KiB
XML
321 lines
8.3 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
<!-- EN-Revision: 4d02fe98ddc684a0d82a3921ef189a71b98f4f04 Maintainer: yannick Status: ready -->
|
|
<!-- Reviewed: no -->
|
|
<refentry xml:id="function.getopt" xmlns="http://docbook.org/ns/docbook">
|
|
<refnamediv>
|
|
<refname>getopt</refname>
|
|
<refpurpose>Lit des options passées dans la ligne de commande</refpurpose>
|
|
</refnamediv>
|
|
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis>
|
|
<type class="union"><type>array</type><type>false</type></type><methodname>getopt</methodname>
|
|
<methodparam><type>string</type><parameter>short_options</parameter></methodparam>
|
|
<methodparam choice="opt"><type>array</type><parameter>long_options</parameter><initializer>[]</initializer></methodparam>
|
|
<methodparam choice="opt"><type>int</type><parameter role="reference">rest_index</parameter><initializer>&null;</initializer></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
<function>getopt</function> lit les options passées dans la ligne de commande.
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>short_options</parameter></term>
|
|
<listitem>
|
|
<simpara>
|
|
Chaque caractère dans cette chaîne sera utilisé en tant que caractères
|
|
optionnels et devra correspondre aux options passées, commençant
|
|
par un tiret simple (<literal>-</literal>).
|
|
</simpara>
|
|
<simpara>
|
|
Par exemple, une chaîne optionnelle <literal>"x"</literal> correspondra
|
|
à l'option <literal>-x</literal>.
|
|
</simpara>
|
|
<simpara>
|
|
Seuls a-z, A-Z et 0-9 sont autorisés.
|
|
</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>long_options</parameter></term>
|
|
<listitem>
|
|
<simpara>
|
|
Un tableau d'options. Chaque élément de ce tableau sera utilisé comme
|
|
option et devra correspondre aux options passées, commençant par un
|
|
tiret double (<literal>--</literal>).
|
|
</simpara>
|
|
<simpara>
|
|
Par exemple, un élément <literal>longopts</literal> <literal>"opt"</literal>
|
|
correspondra à l'option <literal>--opt</literal>.
|
|
</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>rest_index</parameter></term>
|
|
<listitem>
|
|
<simpara>
|
|
Si le paramètre <parameter>rest_index</parameter> est présent, alors l'index
|
|
où l'analyse des arguments s'est arrêtée sera écrit dans cette variable.
|
|
</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
<para>
|
|
Le paramètre <parameter>short_options</parameter> peut contenir les éléments suivants :
|
|
<simplelist>
|
|
<member>Caractères individuels (n'accepte pas de valeur)</member>
|
|
<member>Caractères suivis par un deux-points (le paramètre nécessite une valeur)</member>
|
|
<member>Caractères suivis par deux deux-points (valeur optionnelle)</member>
|
|
</simplelist>
|
|
Les valeurs optionnelles sont les premiers arguments après la chaîne. Si
|
|
une valeur est requise, peu importe que la valeur soit suivi d'un espace ou
|
|
non. Voir la note.
|
|
<note>
|
|
<simpara>
|
|
Les valeurs optionnelles n'acceptent pas l'espace comme séparateur.
|
|
</simpara>
|
|
</note>
|
|
</para>
|
|
<para>
|
|
Le tableau de valeurs <parameter>long_options</parameter> peut contenir :
|
|
<simplelist>
|
|
<member>String (paramètre n'accepte aucune valeur)</member>
|
|
<member>String suivit d'un deux-point (paramètre nécessite une valeur)</member>
|
|
<member>String suivit de deux deux-points (valeur optionnel)</member>
|
|
</simplelist>
|
|
</para>
|
|
<note>
|
|
<para>
|
|
Le format des paramètres <parameter>short_options</parameter> et
|
|
<parameter>long_options</parameter> est identique ; la seule différence est
|
|
que <parameter>long_options</parameter> prend un tableau en option (où chaque élément
|
|
est une option) alors que <parameter>short_options</parameter> prend une chaîne
|
|
(où chaque caractère est une option).
|
|
</para>
|
|
</note>
|
|
</refsect1>
|
|
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
Cette fonction retourne un tableau d'options/arguments, &return.falseforfailure;.
|
|
</para>
|
|
<note>
|
|
<para>
|
|
L'analyse des options s'arrêtera lorsque la première mauvaise
|
|
option sera trouvée, et tout ce qui suivra sera ignoré.
|
|
</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>7.1.0</entry>
|
|
<entry>
|
|
Ajout du paramètre <parameter>rest_index</parameter>.
|
|
</entry>
|
|
</row>
|
|
</tbody>
|
|
</tgroup>
|
|
</informaltable>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example xml:id="getopt.examples-1">
|
|
<title>Exemple avec <function>getopt</function> : les bases</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>Second exemple avec <function>getopt</function> : Introduction aux options longues</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
// Script example.php
|
|
$shortopts = "";
|
|
$shortopts .= "f:"; // Valeur requise
|
|
$shortopts .= "v::"; // Valeur optionnelle
|
|
$shortopts .= "abc"; // Ces options n'acceptent pas de valeur
|
|
|
|
$longopts = array(
|
|
"required:", // Valeur requise
|
|
"optional::", // Valeur optionnelle
|
|
"option", // Aucune valeur
|
|
"opt", // Aucune valeur
|
|
);
|
|
$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>Troisième exemple avec <function>getopt</function> : Passage de plusieurs options</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>
|
|
<para>
|
|
<example xml:id="getopt.examples-4">
|
|
<title>Exemple de <function>getopt</function> : Utilisant <parameter>rest_index</parameter></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
// Script example.php
|
|
$rest_index = null;
|
|
$opts = getopt('a:b:', [], $rest_index);
|
|
$pos_args = array_slice($argv, $rest_index);
|
|
var_dump($pos_args);
|
|
]]>
|
|
</programlisting>
|
|
<programlisting role="shell">
|
|
<![CDATA[
|
|
shell> php example.php -a 1 -b 2 -- test
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs;
|
|
<screen>
|
|
<![CDATA[
|
|
array(1) {
|
|
[0]=>
|
|
string(4) "test"
|
|
}
|
|
]]>
|
|
</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
|
|
-->
|