explode
<<<
fprintf get_html_translation_table
>>>

6.36 Chaînes de caractères (Strings)
6 Référence des fonctions
 Manuel PHP

Introduction
Pré-requis
Installation
Constantes pré-définies
Voir aussi
addcslashes
addslashes
bin2hex
chop
chr
chunk_split
convert_cyr_string
convert_uudecode
convert_uuencode
count_chars
crc32
crypt
echo
explode
->fprintf
get_html_translation_table
hebrev
hebrevc
html_entity_decode
htmlentities
htmlspecialchars_decode
htmlspecialchars
implode
join
levenshtein
localeconv
ltrim
md5_file
md5
metaphone
money_format
nl_langinfo
nl2br
number_format
ord
parse_str
print
printf
quoted_printable_decode
quotemeta
rtrim
setlocale
sha1_file
sha1
similar_text
soundex
sprintf
sscanf
str_ireplace
str_pad
str_repeat
str_replace
str_rot13
str_shuffle
str_split
str_word_count
strcasecmp
strchr
strcmp
strcoll
strcspn
strip_tags
stripcslashes
stripos
stripslashes
stristr
strlen
strnatcasecmp
strnatcmp
strncasecmp
strncmp
strpbrk
strpos
strrchr
strrev
strripos
strrpos
strspn
strstr
strtok
strtolower
strtoupper
strtr
substr_compare
substr_count
substr_replace
substr
trim
ucfirst
ucwords
vfprintf
vprintf
vsprintf
wordwrap

6.36.20 fprintf()Ecrit une chaîne formatée dans un flux

[ Exemples avec fprintf ]   PHP 5

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

fprintf écrit la chaîne produite avec le format format dans le flux représenté par handle . Le format format est décrit dans la documentation de la fonction sprintf .

Retourne la longueur de la chaîne affichée.

Entiers avec zéros initiaux fprintf

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

fprintf($fp, "%04d-%02d-%02d", $year, $month, $day);
// écrira la date formatée ISO dans le fichier date.txt
?>
Format monétaire avec fprintf

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

$money1 = 68.75;
$money2 = 54.35;
$money = $money1 + $money2;
// echo $money affichera "123.1";
$len = fprintf($fp, '%01.2f', $money);
// écrira "123.10" dans le fichier currency.txt

echo "écriture de $len octets dans le fichier currency.txt";
// utilisez la valeur retournée par fprintf pour déterminer le nombre d'octets écrits
?>

Voir aussi printf , sprintf , sscanf , fscanf , vsprintf et number_format .

<< fprintf >>
explode Chaînes de caractères (Strings) get_html_translation_table