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

search for in the

get_html_translation_table> <explode
[edit] Last updated: Sat, 07 Jan 2012

view this page in

fprintf

(PHP 5)

fprintf형식화한 문자열을 스트림에 기록

설명

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

형식화 문자열 format에 따라 생성한 문자열을 handle에 지정한 스트림 리소스에 기록합니다.

인수

handle

일반적으로 fopen()으로 생성하는 파일 시스템 포인터 resource.

format

format 설명은 sprintf()를 참고하십시오.

args

...

반환값

쓰여진 문자열의 길이를 반환합니다.

예제

Example #1 fprintf(): 0을 채운 정수

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

fprintf($fp"%04d-%02d-%02d"$year$month$day);
// date.txt에 형식화한 ISO 날짜를 기록합니다
?>

Example #2 fprintf(): 통화 형식화

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

$money1 68.75;
$money2 54.35;
$money $money1 $money2;
// echo $money 는 "123.1"를 출력합니다;
$len fprintf($fp"%01.2f"$money);
// currency.txt에 "123.10"을 씁니다

echo "wrote $len bytes to currency.txt";
// fprintf의 반환값은 기록한 바이트를 확인할 때 사용합니다
?>

참고

  • printf() - 형식화한 문자열을 출력
  • sprintf() - 형식화한 문자열을 반환
  • sscanf() - 문자열을 형식에 따라 해석
  • fscanf() - Parses input from a file according to a format
  • vsprintf() - Return a formatted string
  • number_format() - Format a number with grouped thousands



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

 
show source | credits | stats | sitemap | contact | advertising | mirror sites