PHP
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

get_html_translation_table> <explode
Last updated: Fri, 22 Aug 2008

view this page in

fprintf

(PHP 5)

fprintfEscribir una cadena con formato a una secuencia

Descripción

int fprintf ( resource $gestor , string $formato [, mixed $args [, mixed $... ]] )

Escribe una cadena producida de acuerdo a formato al recurso de secuencia especificado por gestor .

Lista de parámetros

gestor

formato

Vea sprintf() para una descripción de formato .

args

...

Valores retornados

Devuelve la longitud de la cadena impresa.

Ejemplos

Example #1 fprintf(): enteros con relleno de ceros

<?php
if (!($da fopen('fecha.txt''w')))
    return;

fprintf($da"%04d-%02d-%02d"$anyo$mes$dia);
// escribe la fecha en formato ISO a fecha.txt
?>

Example #2 fprintf(): dando formato a valores monetarios

<?php
if (!($da fopen('monetario.txt''w')))
    return;

$dinero1 68.75;
$dinero2 54.35;
$dinero $dinero1 $dinero2;
// echo $dinero producirá la salida "123.1";
$long fprintf($da'%01.2f'$dinero);
// escribe "123.10" en monetario.txt

echo "se escribieron $long bytes a monetario.txt";
// usar el valor de retorno para determinar cuántos bytes se escribieron
?>



add a note add a note User Contributed Notes
fprintf
jgbreezer at hotmail dot com
07-Sep-2006 07:14
Another alternative using sprintf and fwrite() for pre-v5 php's:

fwrite( resource, sprintf(format [, mixed args [, mixed ...]] ))

Barring slight logical differences in meaning of returned value and (maybe??) how it handles magic_quotes_runtime config option, see fwrite() help.
aidan at php dot net
30-May-2004 10:35
This functionality is now implemented in the PEAR package PHP_Compat.

More information about using this function without upgrading your version of PHP can be found on the below link:

http://pear.php.net/package/PHP_Compat

get_html_translation_table> <explode
Last updated: Fri, 22 Aug 2008
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites