cvs: phpdoc-fr /reference/strings/functions sprintf.xml
| From: | Damien Seguy | Date: | Fri, 28 Jun 2002 17:30:27 +0000 |
| Subject: | cvs: phpdoc-fr /reference/strings/functions sprintf.xml | ||
| Groups: | php.doc.fr | ||
| Request: | Send a blank email to doc-fr+get-2@lists.php.net to get a copy of this message | ||
dams Fri Jun 28 13:30:27 2002 EDT
Modified files:
/phpdoc-fr/reference/strings/functions sprintf.xml
Log:
Correction du comportement par dfaut de sprintf.
Index: phpdoc-fr/reference/strings/functions/sprintf.xml
diff -u phpdoc-fr/reference/strings/functions/sprintf.xml:1.1
phpdoc-fr/reference/strings/functions/sprintf.xml:1.2
--- phpdoc-fr/reference/strings/functions/sprintf.xml:1.1 Sun Apr 14 20:38:44 2002
+++ phpdoc-fr/reference/strings/functions/sprintf.xml Fri Jun 28 13:30:27 2002
@@ -14,8 +14,9 @@
<methodparam
choice="opt"><type>mixed</type><parameter>args</parameter></methodparam>
</methodsynopsis>
<simpara>
- <function>sprintf</function> retourne une chaîne
- formatée avec le format <parameter>format</parameter>.
+ <function>sprintf</function> retourne une chaîne, construite à
+ partir des arguments <parameter>args</parameter>, et formatée
+ avec <parameter>format</parameter>.
</simpara>
<simpara>
La chaîne de format est composée de 0 ou plus directives :
@@ -43,9 +44,9 @@
<simpara>
Un argument optionnel <emphasis>alignment spécifier</emphasis> qui
indique
que le résultat doit être justifié à droite ou
- à gauche. Par défaut, il est justifié à gauche.
+ à droite. Par défaut, il est justifié à gauche.
Le caractère <literal>-</literal> signifie : justification
à
- droite.
+ gauche.
</simpara>
</listitem>
<listitem>
@@ -119,10 +120,12 @@
<example>
<title>Echange d'arguments : cas habituel</title>
<programlisting role="php">
-<?php
-$format = "Il y a %d singes dans le %s";
-printf($format,$num,$location);
-?>
+<![CDATA[
+<?php
+ $format = "Il y a %d singes dans le %s";
+ printf($format,$num,$location);
+?>
+]]>
</programlisting>
</example>
Cela pourra afficher "Il y a 5 singes dans le baobab". Mais imaginons
@@ -132,10 +135,12 @@
<example>
<title>Echange d'arguments : cas problématique</title>
<programlisting role="php">
-<?php
-$format = "Le %s contient %d singes";
-printf($format,$num,$location);
-?>
+<![CDATA[
+<?php
+ $format = "Le %s contient %d singes";
+ printf($format,$num,$location);
+?>
+]]>
</programlisting>
</example>
Maintenant, on a un problème. L'ordre d'utilisation des variables
@@ -148,10 +153,12 @@
<example>
<title>Echange d'arguments : solution</title>
<programlisting role="php">
-<?php
-$format = "Le %2\$s contient %1\$d singes";
-printf($format,$num,$location);
-?>
+<![CDATA[
+<?php
+ $format = "Le %2\$s contient %1\$d singes";
+ printf($format,$num,$location);
+?>
+]]>
</programlisting>
</example>
Et vous pouvez désormais répéter les variables sans ajouter
@@ -159,46 +166,53 @@
<example>
<title>Echange d'arguments : répétition</title>
<programlisting role="php">
-<?php
-$format = "Le %2\$s contient %1\$d singes. C'est un beau %2\$s,
avec %1\$d signes dessus.";
-printf($format,$num,$location);
-?>
+<![CDATA[
+<?php
+ $format = "Le %2\$s contient %1\$d singes.
+ C'est un beau %2\$s, avec %1\$d signes dessus.";
+ printf($format,$num,$location);
+?>
+]]>
</programlisting>
</example>
</para>
- <simpara>
- Voir aussi
- <function>printf</function>,
- <function>sscanf</function>,
- <function>fscanf</function> et
- <function>number_format</function>.
- </simpara>
<para>
<example>
<title>
- Exemple avec <function>sprintf</function>: complété
+ Exemple avec <function>sprintf</function> : complété
avec des zéros
</title>
<programlisting role="php">
-<?php
-$isodate = sprintf("%04d-%02d-%02d", $year, $month, $day);
-?>
+<![CDATA[
+<?php
+ $isodate = sprintf("%04d-%02d-%02d", $year, $month, $day);
+?>
+]]>
</programlisting>
</example>
<example>
<title>Exemple avec <function>sprintf</function>: format
monétaire</title>
<programlisting role="php">
-<?php
-$money1 = 68.75;
-$money2 = 54.35;
-$money = $money1 + $money2;
+<![CDATA[
+<?php
+ $money1 = 68.75;
+ $money2 = 54.35;
+ $money = $money1 + $money2;
// echo $money affichera "123.1";
-$formatted = sprintf("%01.2f", $money);
+ $formatted = sprintf("%01.2f", $money);
// echo $formatted affichera "123.10"
-?>
+?>
+]]>
</programlisting>
</example>
</para>
+ <simpara>
+ Voir aussi
+ <function>printf</function>,
+ <function>sscanf</function>,
+ <function>fscanf</function> et
+ <function>number_format</function>.
+ </simpara>
</refsect1>
</refentry>