Sophie

Sophie

distrib > Mandriva > 9.1 > ppc > by-pkgid > a34ed6838d4b29d38abd504392a4a797 > files > 670

php-manual-es-4.3.0-2mdk.noarch.rpm

<HTML
><HEAD
><TITLE
>fprintf</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
REL="HOME"
TITLE="Manual de PHP"
HREF="index.html"><LINK
REL="UP"
TITLE="Funciones de cadenas"
HREF="ref.strings.html"><LINK
REL="PREVIOUS"
TITLE="explode"
HREF="function.explode.html"><LINK
REL="NEXT"
TITLE="get_html_translation_table"
HREF="function.get-html-translation-table.html"><META
HTTP-EQUIV="Content-type"
CONTENT="text/html; charset=ISO-8859-1"></HEAD
><BODY
CLASS="refentry"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>Manual de PHP</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="function.explode.html"
ACCESSKEY="P"
>Anterior</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="function.get-html-translation-table.html"
ACCESSKEY="N"
>Siguiente</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><H1
><A
NAME="function.fprintf"
></A
>fprintf</H1
><DIV
CLASS="refnamediv"
><A
NAME="AEN74457"
></A
><P
>    (PHP 5 CVS only)</P
>fprintf&nbsp;--&nbsp;Write a formatted string to a stream</DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN74460"
></A
><H2
>Description</H2
>int <B
CLASS="methodname"
>fprintf</B
> ( resource handle, string format [, mixed args])<BR
></BR
><P
>&#13;     Write a string produced according to the formatting string
     <TT
CLASS="parameter"
><I
>format</I
></TT
> to the stream resource specified
     by <TT
CLASS="parameter"
><I
>handle</I
></TT
>..
    </P
><P
>&#13;     The format string is composed of zero or more directives:
     ordinary characters (excluding <TT
CLASS="literal"
>%</TT
>) that are
     copied directly to the result, and <SPAN
CLASS="emphasis"
><I
CLASS="emphasis"
>conversion
     specifications</I
></SPAN
>, each of which results in fetching its
     own parameter.  This applies to <B
CLASS="function"
>fprintf()</B
>,
     <A
HREF="function.sprintf.html"
><B
CLASS="function"
>sprintf()</B
></A
>, and <A
HREF="function.printf.html"
><B
CLASS="function"
>printf()</B
></A
>.
    </P
><P
>&#13;     Each conversion specification consists of a percent sign
     (<TT
CLASS="literal"
>%</TT
>), followed by one or more of these
     elements, in order:
     <P
></P
><OL
TYPE="1"
><LI
><P
>&#13;        An optional <SPAN
CLASS="emphasis"
><I
CLASS="emphasis"
>padding specifier</I
></SPAN
> that says
        what character will be used for padding the results to the
        right string size.  This may be a space character or a
        <TT
CLASS="literal"
>0</TT
> (zero character).  The default is to pad
        with spaces.  An alternate padding character can be specified
        by prefixing it with a single quote (<TT
CLASS="literal"
>'</TT
>).
        See the examples below.
       </P
></LI
><LI
><P
>&#13;        An optional <SPAN
CLASS="emphasis"
><I
CLASS="emphasis"
>alignment specifier</I
></SPAN
> that says
        if the result should be left-justified or right-justified.
        The default is right-justified; a <TT
CLASS="literal"
>-</TT
>
        character here will make it left-justified.
       </P
></LI
><LI
><P
>&#13;        An optional number, a <SPAN
CLASS="emphasis"
><I
CLASS="emphasis"
>width specifier</I
></SPAN
>
        that says how many characters (minimum) this conversion should
        result in.
       </P
></LI
><LI
><P
>&#13;        An optional <SPAN
CLASS="emphasis"
><I
CLASS="emphasis"
>precision specifier</I
></SPAN
> that says
        how many decimal digits should be displayed for floating-point
        numbers.  This option has no effect for other types than
        <A
HREF="language.types.float.html"
><B
CLASS="type"
>float</B
></A
>. (Another function useful for formatting numbers is
        <A
HREF="function.number-format.html"
><B
CLASS="function"
>number_format()</B
></A
>.)
       </P
></LI
><LI
><P
>&#13;        A <SPAN
CLASS="emphasis"
><I
CLASS="emphasis"
>type specifier</I
></SPAN
> that says what type the
        argument data should be treated as.  Possible types:
        <P
></P
><TABLE
BORDER="0"
><TBODY
><TR
><TD
>&#13;          <TT
CLASS="literal"
>%</TT
> - a literal percent character. No
          argument is required.
         </TD
></TR
><TR
><TD
>&#13;          <TT
CLASS="literal"
>b</TT
> - the argument is treated as an
          integer, and presented as a binary number.
         </TD
></TR
><TR
><TD
>&#13;          <TT
CLASS="literal"
>c</TT
> - the argument is treated as an
          integer, and presented as the character with that ASCII
          value.
         </TD
></TR
><TR
><TD
>&#13;          <TT
CLASS="literal"
>d</TT
> - the argument is treated as an
          integer, and presented as a (signed) decimal number.
         </TD
></TR
><TR
><TD
>&#13;          <TT
CLASS="literal"
>u</TT
> - the argument is treated as an
          integer, and presented as an unsigned decimal number.
         </TD
></TR
><TR
><TD
>&#13;          <TT
CLASS="literal"
>f</TT
> - the argument is treated as a
          <A
HREF="language.types.float.html"
><B
CLASS="type"
>float</B
></A
>, and presented as a floating-point number.
         </TD
></TR
><TR
><TD
>&#13;          <TT
CLASS="literal"
>o</TT
> - the argument is treated as an
          integer, and presented as an octal number.
         </TD
></TR
><TR
><TD
>&#13;          <TT
CLASS="literal"
>s</TT
> - the argument is treated as and
          presented as a string.
         </TD
></TR
><TR
><TD
>&#13;          <TT
CLASS="literal"
>x</TT
> - the argument is treated as an integer
          and presented as a hexadecimal number (with lowercase
          letters).
         </TD
></TR
><TR
><TD
>&#13;          <TT
CLASS="literal"
>X</TT
> - the argument is treated as an integer
          and presented as a hexadecimal number (with uppercase
          letters).
         </TD
></TR
></TBODY
></TABLE
><P
></P
>
       </P
></LI
></OL
>
    </P
><P
>&#13;     See also: <A
HREF="function.printf.html"
><B
CLASS="function"
>printf()</B
></A
>,
     <A
HREF="function.sprintf.html"
><B
CLASS="function"
>sprintf()</B
></A
>,
     <A
HREF="function.sscanf.html"
><B
CLASS="function"
>sscanf()</B
></A
>, <A
HREF="function.fscanf.html"
><B
CLASS="function"
>fscanf()</B
></A
>, 
     <A
HREF="function.vsprintf.html"
><B
CLASS="function"
>vsprintf()</B
></A
>, and
     <A
HREF="function.number-format.html"
><B
CLASS="function"
>number_format()</B
></A
>.
    </P
></DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN74535"
></A
><H2
>Examples</H2
><P
>&#13;     <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN74538"
></A
><P
><B
>Ejemplo 1. <A
HREF="function.sprintf.html"
><B
CLASS="function"
>sprintf()</B
></A
>: zero-padded integers</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="php"
>$isodate = sprintf("%04d-%02d-%02d", $year, $month, $day);</PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
>
     <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN74542"
></A
><P
><B
>Ejemplo 2. <A
HREF="function.sprintf.html"
><B
CLASS="function"
>sprintf()</B
></A
>: formatting currency</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="php"
>$money1 = 68.75;
$money2 = 54.35;
$money = $money1 + $money2;
// echo $money will output "123.1";
$formatted = sprintf("%01.2f", $money);
// echo $formatted will output "123.10"</PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
>
    </P
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="function.explode.html"
ACCESSKEY="P"
>Anterior</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Inicio</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="function.get-html-translation-table.html"
ACCESSKEY="N"
>Siguiente</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>explode</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="ref.strings.html"
ACCESSKEY="U"
>Subir</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>get_html_translation_table</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>