reference/strings/functions/printf.xml
099842f34289b4cf932863e1f83d0e9a144d3b06
...
...
@@ -11,8 +11,7 @@
11
11
<methodsynopsis>
12
12
<type>int</type><methodname>printf</methodname>
13
13
<methodparam><type>string</type><parameter>format</parameter></methodparam>
14
-
<methodparam choice="opt"><type>mixed</type><parameter>args</parameter></methodparam>
15
-
<methodparam choice="opt"><type>mixed</type><parameter>...</parameter></methodparam>
14
+
<methodparam rep="repeat"><type>mixed</type><parameter>values</parameter></methodparam>
16
15
</methodsynopsis>
17
16
<simpara>
18
17
Produces output according to <parameter>format</parameter>.
...
...
@@ -23,24 +22,9 @@
23
22
&reftitle.parameters;
24
23
<para>
25
24
<variablelist>
25
+
&strings.parameter.format;
26
26
<varlistentry>
27
-
<term><parameter>format</parameter></term>
28
-
<listitem>
29
-
<para>
30
-
See <function>sprintf</function> for a description of
31
-
<parameter>format</parameter>.
32
-
</para>
33
-
</listitem>
34
-
</varlistentry>
35
-
<varlistentry>
36
-
<term><parameter>args</parameter></term>
37
-
<listitem>
38
-
<para>
39
-
</para>
40
-
</listitem>
41
-
</varlistentry>
42
-
<varlistentry>
43
-
<term><parameter>...</parameter></term>
27
+
<term><parameter>values</parameter></term>
44
28
<listitem>
45
29
<para>
46
30
</para>
...
...
@@ -57,15 +41,116 @@
57
41
</para>
58
42
</refsect1>
59
43

44
+
<refsect1 role="errors">
45
+
&reftitle.errors;
46
+
&strings.errors.sprintf;
47
+
</refsect1>
48
+

49
+
<refsect1 role="changelog">
50
+
&reftitle.changelog;
51
+
&strings.changelog.sprintf;
52
+
</refsect1>
53
+

54
+
<refsect1 role="examples">
55
+
&reftitle.examples;
56
+
<para>
57
+
<example>
58
+
<title><function>printf</function>: various examples</title>
59
+
<programlisting role="php">
60
+
<![CDATA[
61
+
<?php
62
+
$n = 43951789;
63
+
$u = -43951789;
64
+
$c = 65; // ASCII 65 is 'A'
65
+

66
+
// notice the double %%, this prints a literal '%' character
67
+
printf("%%b = '%b'\n", $n); // binary representation
68
+
printf("%%c = '%c'\n", $c); // print the ascii character, same as chr() function
69
+
printf("%%d = '%d'\n", $n); // standard integer representation
70
+
printf("%%e = '%e'\n", $n); // scientific notation
71
+
printf("%%u = '%u'\n", $n); // unsigned integer representation of a positive integer
72
+
printf("%%u = '%u'\n", $u); // unsigned integer representation of a negative integer
73
+
printf("%%f = '%f'\n", $n); // floating point representation
74
+
printf("%%o = '%o'\n", $n); // octal representation
75
+
printf("%%s = '%s'\n", $n); // string representation
76
+
printf("%%x = '%x'\n", $n); // hexadecimal representation (lower-case)
77
+
printf("%%X = '%X'\n", $n); // hexadecimal representation (upper-case)
78
+

79
+
printf("%%+d = '%+d'\n", $n); // sign specifier on a positive integer
80
+
printf("%%+d = '%+d'\n", $u); // sign specifier on a negative integer
81
+
?>
82
+
]]>
83
+
</programlisting>
84
+
&example.outputs;
85
+
<screen>
86
+
<![CDATA[
87
+
%b = '10100111101010011010101101'
88
+
%c = 'A'
89
+
%d = '43951789'
90
+
%e = '4.39518e+7'
91
+
%u = '43951789'
92
+
%u = '4251015507'
93
+
%f = '43951789.000000'
94
+
%o = '247523255'
95
+
%s = '43951789'
96
+
%x = '29ea6ad'
97
+
%X = '29EA6AD'
98
+
%+d = '+43951789'
99
+
%+d = '-43951789'
100
+
]]>
101
+
</screen>
102
+
</example>
103
+

104
+
<example>
105
+
<title><function>printf</function>: string specifiers</title>
106
+
<programlisting role="php">
107
+
<![CDATA[
108
+
<?php
109
+
$s = 'monkey';
110
+
$t = 'many monkeys';
111
+

112
+
printf("[%s]\n", $s); // standard string output
113
+
printf("[%10s]\n", $s); // right-justification with spaces
114
+
printf("[%-10s]\n", $s); // left-justification with spaces
115
+
printf("[%010s]\n", $s); // zero-padding works on strings too
116
+
printf("[%'#10s]\n", $s); // use the custom padding character '#'
117
+
printf("[%'#*s]\n", 10, $s); // Provide the padding width as an additional argument
118
+
printf("[%10.9s]\n", $t); // right-justification but with a cutoff of 8 characters
119
+
printf("[%-10.9s]\n", $t); // left-justification but with a cutoff of 8 characters
120
+
?>
121
+
]]>
122
+
</programlisting>
123
+
&example.outputs;
124
+
<screen>
125
+
<![CDATA[
126
+
[monkey]
127
+
[ monkey]
128
+
[monkey ]
129
+
[0000monkey]
130
+
[####monkey]
131
+
[####monkey]
132
+
[ many monk]
133
+
[many monk ]
134
+
]]>
135
+
</screen>
136
+
</example>
137
+
</para>
138
+
</refsect1>
139
+

60
140
<refsect1 role="seealso">
61
141
&reftitle.seealso;
62
142
<para>
63
143
<simplelist>
64
144
<member><function>print</function></member>
65
145
<member><function>sprintf</function></member>
146
+
<member><function>fprintf</function></member>
66
147
<member><function>vprintf</function></member>
148
+
<member><function>vsprintf</function></member>
149
+
<member><function>vfprintf</function></member>
67
150
<member><function>sscanf</function></member>
68
151
<member><function>fscanf</function></member>
152
+
<member><function>number_format</function></member>
153
+
<member><function>date</function></member>
69
154
<member><function>flush</function></member>
70
155
</simplelist>
71
156
</para>
72
157