FileUtf8
in component
Reads and writes files in different charsets through UTF-8 conversion filters. It handles BOM and MacOS line endings.
Table of Contents
Properties
Methods
- fclose() : bool
- Closes the file.
- fopen() : resource|false|null
- Opens a file and appends charset conversion filters.
- fseek() : int
- Moves the file pointer to the offset. When conversion filters are applied the file is read from
the beginning up to the offset. - getLastError() : string
- Returns the last error.
- rewind() : void
- Moves the file pointer to the beginning of the file data (after BOM).
Properties
$handle
public
mixed
$handle
= null
$bom_size
protected
mixed
$bom_size
= 0
$charset
protected
mixed
$charset
= ''
$filename
protected
mixed
$filename
= ''
$filter
protected
mixed
$filter
= null
$is_filter_applied
protected
mixed
$is_filter_applied
= false
$lastError
protected
mixed
$lastError
= ''
$options
protected
mixed
$options
= array()
Methods
fclose()
Closes the file.
public
fclose() : bool
Return values
boolfopen()
Opens a file and appends charset conversion filters.
public
fopen(mixed $filename, mixed $mode[, mixed $options = array() ][, mixed $charset = 'UTF-8' ]) : resource|false|null
$filename — file path. $mode — 'r', 'w' or 'a'. $options — array of options: enable_macfix — convert MacOS line endings on reading. $charset — file charset.
Parameters
- $filename : mixed
- $mode : mixed
- $options : mixed = array()
- $charset : mixed = 'UTF-8'
Return values
resource|false|null —File handle; false on error (see getLastError()).
fseek()
Moves the file pointer to the offset. When conversion filters are applied the file is read from the beginning up to the offset.
public
fseek(mixed $offset) : int
Notes: fseek works in bytes always (regardless of the stream encoding), ftell measures length in bytes for UTF-8 charset, fread reads a number of utf characters (not bytes).
$offset — offset in bytes.
Parameters
- $offset : mixed
Return values
int —0 on success, -1 on error.
getLastError()
Returns the last error.
public
getLastError() : string
Return values
stringrewind()
Moves the file pointer to the beginning of the file data (after BOM).
public
rewind() : void