The recode_file function will put the file position indicator at the end of each files, so if you want to re-use the handles use fseek beforehand.
PHP - Manual: recode_file
2024-12-22
(PHP 4, PHP 5, PHP 7 < 7.4.0)
recode_file — Recode from file to file according to recode request
$request
, resource $input
, resource $output
): bool
Recode the file referenced by file handle
input
into the file referenced by file
handle output
according to the recode
request
.
request
The desired recode request type
input
A local file handle resource for
the input
output
A local file handle resource for
the output
Returns false
, if unable to comply, true
otherwise.
示例 #1 Basic recode_file() example
<?php
$input = fopen('input.txt', 'r');
$output = fopen('output.txt', 'w');
recode_file("us..flat", $input, $output);
?>
This function does not currently process file handles referencing remote files (URLs). Both file handles must refer to local files.
The recode_file function will put the file position indicator at the end of each files, so if you want to re-use the handles use fseek beforehand.