trait ReadTrait

Class Read

Methods

static array|bool
load(string $src, string $format = self::FORMAT_PHP)

No description

static array
loadPhp(string $file, bool $throwError = true)

load array data form file.

static array
loadJson(string $file)

No description

static array|bool
loadIni(string $ini)

No description

static array|bool
loadYml(string $yml)

No description

static array|string
readAllLine($file, bool|true $filter = true)

No description

static array
readLines(string $fileName, int $startLine = 1, int $endLine = 10, string $mode = 'rb')

getLines 获取文件一定范围内的内容

static array
readSymmetry(string $fileName, integer $current = 1, integer $lineNum = 3)

symmetry 得到当前行对称上下几($lineNum)行的内容

static array
readRangeLines(string $file, int $baseLine, int $prevLines = 3, int $nextLines = 3)

No description

static array
getLines5u3d(string $file, int $baseLine = 1)

得到基准行数上5行下3行的内容, lines up and down

static array
tail(resource $fp, int $n, int $base = 5)

读取文件的最后几行(支持大文件读取)

Details

at line 31
static array|bool load(string $src, string $format = self::FORMAT_PHP)

Parameters

string $src 要解析的 文件 或 字符串内容。
string $format

Return Value

array|bool

Exceptions

FileNotFoundException

at line 64
static array loadPhp(string $file, bool $throwError = true)

load array data form file.

Parameters

string $file
bool $throwError

Return Value

array

Exceptions

FileNotFoundException

at line 85
static array loadJson(string $file)

Parameters

string $file

Return Value

array

at line 94
static array|bool loadIni(string $ini)

Parameters

string $ini 要解析的 ini 文件名 或 字符串内容。

Return Value

array|bool

at line 103
static array|bool loadYml(string $yml)

Parameters

string $yml 要解析的 yml 文件名 或 字符串内容。

Return Value

array|bool

at line 115
static array|string readAllLine($file, bool|true $filter = true)

Parameters

$file
bool|true $filter

Return Value

array|string

Exceptions

FileNotFoundException
FileReadException

at line 137
static array readLines(string $fileName, int $startLine = 1, int $endLine = 10, string $mode = 'rb')

getLines 获取文件一定范围内的内容

Parameters

string $fileName 含完整路径的文件
int $startLine 开始行数 默认第1行
int $endLine 结束行数 默认第50行
string $mode 打开文件方式

Return Value

array 返回内容

Exceptions

FileSystemException

at line 191
static array readSymmetry(string $fileName, integer $current = 1, integer $lineNum = 3)

symmetry 得到当前行对称上下几($lineNum)行的内容

Parameters

string $fileName 含完整路径的文件
integer $current [当前行数]
integer $lineNum [获取行数] = $lineNum*2+1

Return Value

array

Exceptions

FileSystemException

at line 212
static array readRangeLines(string $file, int $baseLine, int $prevLines = 3, int $nextLines = 3)

Parameters

string $file
int $baseLine
int $prevLines
int $nextLines

Return Value

array

Exceptions

FileSystemException

at line 227
static array getLines5u3d(string $file, int $baseLine = 1)

得到基准行数上5行下3行的内容, lines up and down

Parameters

string $file
int $baseLine 基准行数

Return Value

array

Exceptions

FileSystemException

at line 240
static array tail(resource $fp, int $n, int $base = 5)

读取文件的最后几行(支持大文件读取)

Parameters

resource $fp e.g fopen("access.log", "r+")
int $n
int $base

Return Value

array