本文整理汇总了PHP中SplFileObject::fgetc方法的典型用法代码示例。如果您正苦于以下问题:PHP SplFileObject::fgetc方法的具体用法?PHP SplFileObject::fgetc怎么用?PHP SplFileObject::fgetc使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SplFileObject
的用法示例。
在下文中一共展示了SplFileObject::fgetc方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: readBytes
private function readBytes($length)
{
$stream = null;
for ($cc = 0; $cc < $length; $cc++) {
if ($this->file->eof()) {
return null;
}
$stream .= $this->file->fgetc();
}
return $stream;
}
示例2: _skipBom
/**
* Skip any BOM in the file
*/
private function _skipBom()
{
$bom = $this->_file->fgetc() . $this->_file->fgetc() . $this->_file->fgetc();
// If there is no bom, then remove bom will return a 3 character string.
// In that case the file position must be reset to the start of the file
if (\MUtil_Encoding::removeBOM($bom)) {
$this->_file->rewind();
}
}
示例3: goBeforeCharacter
/**
* {@inheritdoc}
*/
public function goBeforeCharacter(\SplFileObject $file, $characterNumber)
{
$file->rewind();
if ($characterNumber < 0 || $characterNumber > $file->getSize()) {
throw new OutOfBoundsException();
}
for ($i = 0; $i <= $characterNumber - 1; $i++) {
$file->fgetc();
}
return $file;
}
示例4: test
function test($name)
{
echo "==={$name}===\n";
$o = new SplFileObject(dirname(__FILE__) . '/' . $name);
var_dump($o->key());
while (($c = $o->fgetc()) !== false) {
var_dump($o->key(), $c, $o->eof());
}
echo "===EOF?===\n";
var_dump($o->eof());
var_dump($o->key());
var_dump($o->eof());
}
示例5: readLines
/**
* @param \SplFileObject $file
*
* @return \Generator
*/
private function readLines($file)
{
$pos = -1;
$currentLine = '';
while (-1 !== $file->fseek($pos, SEEK_END)) {
$char = $file->fgetc();
if (PHP_EOL === $char) {
(yield $currentLine);
$currentLine = '';
} else {
$currentLine = $char . $currentLine;
}
$pos--;
}
if (strlen($currentLine) > 0) {
(yield $currentLine);
}
}
示例6: readLong
/**
* @param \SplFileObject $file
* @return int
*/
private function readLong($file)
{
$stream = null;
for ($cc = 0; $cc < 4; $cc++) {
if ($file->eof()) {
return null;
}
$stream .= $file->fgetc();
}
$data = unpack("Nskip", $stream);
return $data['skip'];
}
示例7: peek
/**
* Get the next character from the input stream, without gettng it.
*
* @return string The next character from the specified input stream, without advancing the position
* in the underlying file.
* @see $in
* @see get()
*/
function peek()
{
if ($this->isString) {
if ($this->inPos < $this->inLength) {
$c = $this->in[$this->inPos];
} else {
return EOF;
}
} else {
// Get next input character
$c = $this->in->fgetc();
// Regress position in file
$this->in->fseek(-1, SEEK_CUR);
// Return character obtained
}
return $c;
}
示例8: getNextCharacterContent
/**
* {@inheritdoc}
*/
public function getNextCharacterContent(\SplFileObject $file)
{
$originalPosition = $file->ftell();
$character = $file->fgetc();
$this->walker->goBeforeCharacter($file, $originalPosition);
return $character;
}
示例9: getCharacter
/**
* Gets a character from the given resource.
*
* @throws \YapepBase\Exception\File\Exception In case the object does not have an opened file.
*
* @return string|bool The character, or FALSE if the pointer is at the end of the resource.
*/
public function getCharacter()
{
$this->checkIfFileOpened();
return $this->splFile->fgetc();
}