mirror of
https://github.com/php/doc-zh.git
synced 2026-03-24 23:22:14 +01:00
183 lines
4.7 KiB
XML
183 lines
4.7 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
<!-- EN-Revision: 49999607f48c5e18ef3954a9c6895adbd6aec27a Maintainer: daijie Status: ready -->
|
|
<!-- CREDITS: mowangjuanzi, Luffy -->
|
|
<refentry xmlns="http://docbook.org/ns/docbook" xml:id="function.printf">
|
|
<refnamediv>
|
|
<refname>printf</refname>
|
|
<refpurpose>输出格式化字符串</refpurpose>
|
|
</refnamediv>
|
|
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis>
|
|
<type>int</type><methodname>printf</methodname>
|
|
<methodparam><type>string</type><parameter>format</parameter></methodparam>
|
|
<methodparam rep="repeat"><type>mixed</type><parameter>values</parameter></methodparam>
|
|
</methodsynopsis>
|
|
<simpara>
|
|
依据 <parameter>format</parameter> 格式参数产生输出。
|
|
</simpara>
|
|
</refsect1>
|
|
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
&strings.parameter.format;
|
|
<varlistentry>
|
|
<term><parameter>values</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
返回输出字符串的长度。
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="errors">
|
|
&reftitle.errors;
|
|
&strings.errors.sprintf;
|
|
</refsect1>
|
|
|
|
<refsect1 role="changelog">
|
|
&reftitle.changelog;
|
|
&strings.changelog.sprintf;
|
|
</refsect1>
|
|
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title><function>printf</function>:多种 format 格式的示例</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$n = 43951789;
|
|
$u = -43951789;
|
|
$c = 65; // ASCII 65 is 'A'
|
|
|
|
// 注意两个 %% 的情况,这会打印一个字面上的 '%' 字符
|
|
printf("%%b = '%b'\n", $n); // 二进制表示
|
|
printf("%%c = '%c'\n", $c); // 打印 ascii 字符,与 chr() 函数相同
|
|
printf("%%d = '%d'\n", $n); // 标准整数表示
|
|
printf("%%e = '%e'\n", $n); // 科学计数法
|
|
printf("%%u = '%u'\n", $n); // 无符号正整数表示
|
|
printf("%%u = '%u'\n", $u); // 无符号负整数表示
|
|
printf("%%f = '%f'\n", $n); // 浮点数表示
|
|
printf("%%o = '%o'\n", $n); // 八进制表示
|
|
printf("%%s = '%s'\n", $n); // 字符串表示
|
|
printf("%%x = '%x'\n", $n); // 十六进制表示(小写)
|
|
printf("%%X = '%X'\n", $n); // 十六进制表示(大写)
|
|
|
|
printf("%%+d = '%+d'\n", $n); // 正整数上的符号说明符
|
|
printf("%%+d = '%+d'\n", $u); // 负整数上的符号说明符
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs;
|
|
<screen>
|
|
<![CDATA[
|
|
%b = '10100111101010011010101101'
|
|
%c = 'A'
|
|
%d = '43951789'
|
|
%e = '4.39518e+7'
|
|
%u = '43951789'
|
|
%u = '4251015507'
|
|
%f = '43951789.000000'
|
|
%o = '247523255'
|
|
%s = '43951789'
|
|
%x = '29ea6ad'
|
|
%X = '29EA6AD'
|
|
%+d = '+43951789'
|
|
%+d = '-43951789'
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
|
|
<example>
|
|
<title><function>printf</function>:字符串说明符</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$s = 'monkey';
|
|
$t = 'many monkeys';
|
|
|
|
printf("[%s]\n", $s); // 标准字符串输出
|
|
printf("[%10s]\n", $s); // 带空格的右对齐
|
|
printf("[%-10s]\n", $s); // 带空格的左对齐
|
|
printf("[%010s]\n", $s); // 零填充也适用于字符串
|
|
printf("[%'#10s]\n", $s); // 使用自定义填充字符“#”
|
|
printf("[%'#*s]\n", 10, $s); // 提供填充的宽度作为附加参数
|
|
printf("[%10.9s]\n", $t); // 右对齐,但截断 9 个字符
|
|
printf("[%-10.9s]\n", $t); // 左对齐,但截断 9 个字符
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs;
|
|
<screen>
|
|
<![CDATA[
|
|
[monkey]
|
|
[ monkey]
|
|
[monkey ]
|
|
[0000monkey]
|
|
[####monkey]
|
|
[####monkey]
|
|
[ many monk]
|
|
[many monk ]
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="seealso">
|
|
&reftitle.seealso;
|
|
<para>
|
|
<simplelist>
|
|
<member><function>print</function></member>
|
|
<member><function>sprintf</function></member>
|
|
<member><function>fprintf</function></member>
|
|
<member><function>vprintf</function></member>
|
|
<member><function>vsprintf</function></member>
|
|
<member><function>vfprintf</function></member>
|
|
<member><function>sscanf</function></member>
|
|
<member><function>fscanf</function></member>
|
|
<member><function>number_format</function></member>
|
|
<member><function>date</function></member>
|
|
<member><function>flush</function></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
|
|
-->
|