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
Links
Filesystem
- basename
- chgrp
- chmod
- chown
- clearstatcache
- copy
- dirname
- disk_free_space
- disk_total_space
- diskfreespace
- fclose
- feof
- fflush
- fgetc
- fgetcsv
- fgets
- file
- file_exists
- file_get_contents
- file_put_contents
- fileatime
- filectime
- filegroup
- fileinode
- filemtime
- fileowner
- fileperms
- filesize
- filetype
- flock
- fnmatch
- fopen
- fpassthru
- fputcsv
- fputs
- fread
- fscanf
- fseek
- fstat
- ftell
- ftruncate
- glob
- is_dir
- is_executable
- is_file
- is_link
- is_readable
- is_uploaded_file
- is_writable
- is_writeable
- lchgrp
- lchown
- link
- linkinfo
- lstat
- mkdir
- move_uploaded_file
- pathinfo
- pclose
- popen
- readfile
- readlink
- realpath
- realpath_cache_get
- realpath_cache_size
- rename
- rewind
- rmdir
- set_file_buffer
- stat
- symlink
- tempnam
- tmpfile
- touch
- umask
- unlink