Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

fwrite

Description

The fwrite of Filesystem for PHP binary-safe file write.

Syntax

fwrite(
    resource $stream,
    string $data,
    ?int $length = null
): int|false

Parameters

stream

A file system pointer resource that is typically created using fopen().

data

The string that is to be written.

length

If length is an int, writing will stop after length bytes have been written or the end of data is reached, whichever comes first.

Return

Returns the number of bytes written, or false on failure.

Examples

1 · stream data

<?

$filename = $_SERVER['DOCUMENT_ROOT'] . '/assets/txt/1.txt';
$mode = 'w';

$stream = fopen($filename, $mode);

    $data = 'hello';

    $return = fwrite($stream, $data);

    var_export($return);

fclose($stream);

?>
5

2 · length

<?

$filename = $_SERVER['DOCUMENT_ROOT'] . '/assets/txt/1.txt';
$mode = 'w';

$stream = fopen($filename, $mode);

    $data = 'hello';
    $length = 2;

    $return = fwrite($stream, $data, $length);

    var_export($return);

fclose($stream);

?>
2
HomeMenu