File writing and reading are essential capabilities for various languages, PHP
has built-in# The ##fprintf() function can write the formatted string into the stream. This article will take you to take a look at how to use the
fprintf() function to modify the data. Write.
1. Syntax:
fprintf(resource $handle, string $format, mixed $arg1, $atg2...)
int).
<br/>
% symbols than
$arg arguments, placeholders must be used. The placeholder is inserted after the
% symbol and consists of numbers followed by "
\$".
2. Code example:
Create a new text1.text with empty content<br/>
<br/>
<?php $number = 9; $str = "Are you OK?"; $file = fopen("test1.txt","w"); echo fprintf($file,"There are %u Not OK in %s.",$number,$str); //输出:34 ?>
text1.php内容:There are 9 Not OK in Are you OK?.
Recommended: 《2021 PHP interview questions summary (collection)》《php video tutorial》
The above is the detailed content of Analysis of the fprintf() function in PHP (with detailed code explanation). For more information, please follow other related articles on the PHP Chinese website!