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, 15 Aug 2008

view this page in

fprintf

(PHP 5)

fprintfフォーマットされた文字列をストリームに書き込む

説明

int fprintf ( resource $handle , string $format [, mixed $args [, mixed $... ]] )

format によって作成された文字列を handle で指定したストリームに書き込みます。

パラメータ

handle

fopen() を使用して作成したファイルシステムポインタリソース。

format

format については、 sprintf() のドキュメントで説明されています。

args

...

返り値

書き込まれた文字列の長さを返します。

例1 fprintf(): 数値のゼロ埋め

<?php
if (!($fp fopen('currency.txt''w'))) {
    return;
}

fprintf($fp"%04d-%02d-%02d"$year$month$day);
// ISO 形式にフォーマットした日付を date.txt に書き込みます
?>

例2 fprintf(): 金額のフォーマット

<?php
if (!($fp fopen('date.txt''w'))) {
    return;
}

$money1 68.75;
$money2 54.35;
$money $money1 $money2;
// echo $money は "123.1" を出力します
$len fprintf($fp'%01.2f'$money);
// "123.10" を currency.txt に書き込みます

echo "$len バイトを currency.txt に書き込みました";
// fprintf の返り値を使用して、書き込まれたバイト数を取得します
?>



add a note add a note User Contributed Notes
fprintf
jgbreezer at hotmail dot com
07-Sep-2006 04: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 07: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, 15 Aug 2008
 
 
show source | credits | sitemap | contact | advertising | mirror sites