本文整理汇总了PHP中fgetc函数的典型用法代码示例。如果您正苦于以下问题:PHP fgetc函数的具体用法?PHP fgetc怎么用?PHP fgetc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了fgetc函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_last_log_line
function get_last_log_line($filename)
{
$line = false;
$f = false;
if (file_exists($filename)) {
$f = @fopen($filename, 'r');
}
if ($f === false) {
return false;
} else {
$cursor = -1;
fseek($f, $cursor, SEEK_END);
$char = fgetc($f);
/**
* Trim trailing newline chars of the file
*/
while ($char === "\n" || $char === "\r") {
fseek($f, $cursor--, SEEK_END);
$char = fgetc($f);
}
/**
* Read until the start of file or first newline char
*/
while ($char !== false && $char !== "\n" && $char !== "\r") {
/**
* Prepend the new char
*/
$line = $char . $line;
fseek($f, $cursor--, SEEK_END);
$char = fgetc($f);
}
}
return $line;
}
示例2: executeSqlFile
function executeSqlFile(&$installQ, $filename, $tablePrfx = "")
{
$fp = fopen($filename, "r");
# show error if file could not be opened
if ($fp == false) {
echo "Error reading file " . H($filename) . ".<br>\n";
return false;
} else {
$sqlStmt = "";
while (!feof($fp)) {
$char = fgetc($fp);
if ($char == ";") {
//replace table prefix
$sql = str_replace("%prfx%", $tablePrfx, $sqlStmt);
echo "lara";
echo "process sql [" . $sqlStmt . "]<br>";
//test
$result = $installQ->exec($sql);
if ($installQ->errorOccurred()) {
$installQ->close();
displayErrorPage($installQ);
fclose($fp);
return false;
}
$sqlStmt = "";
} else {
$sqlStmt = $sqlStmt . $char;
}
}
fclose($fp);
return true;
}
}
示例3: read_history
function read_history($history_file, $history_pos, $repo_path)
{
$fp = fopen($history_file, "r") or die("Unable to open file!");
$pos = -2;
// Skip final new line character (Set to -1 if not present)
$lines = array();
$currentLine = '';
while (-1 !== fseek($fp, $pos, SEEK_END)) {
$char = fgetc($fp);
if (PHP_EOL == $char) {
$lines[] = $currentLine;
$currentLine = '';
} else {
$currentLine = $char . $currentLine;
}
$pos--;
}
list($result, $build_id, $branch, $commit_id, $ci_pipeline_time) = split('[|]', $lines[$history_pos]);
list($dummy, $result) = split('[:]', $result);
$result = trim($result);
list($dummy, $build_id) = split('[:]', $build_id);
$build_id = trim($build_id);
list($dummy, $branch) = split('[:]', $branch);
$branch = trim($branch);
list($dummy, $commit_id) = split('[:]', $commit_id);
$commit_id = substr(trim($commit_id), -10);
list($dummy, $ci_pipeline_time) = split('[:]', $ci_pipeline_time);
$ci_pipeline_time = substr(trim($ci_pipeline_time), -10);
$history = array("result" => $result, "build_id" => $build_id, "branch" => $branch, "commit_id" => $commit_id, "artifact_path" => "{$repo_path}/ci_fuel_opnfv/artifact/{$branch}/{$build_id}", "log" => "{$repo_path}/ci_fuel_opnfv/artifact/{$branch}/{$build_id}/ci.log", "iso" => "{$repo_path}/ci_fuel_opnfv/artifact/{$branch}/{$build_id}/opnfv-{$build_id}.iso", "ci_pipeline_time" => $ci_pipeline_time);
return $history;
}
示例4: setDomainAddress
function setDomainAddress($domain, $address, $server, $ttl = 86400)
{
$process = proc_open('/usr/bin/nsupdate', array(array('pipe', 'r'), array('pipe', 'w'), array('pipe', 'w')), $pipes);
if (is_resource($process)) {
fwrite($pipes[0], "server {$server}\n");
fwrite($pipes[0], "update delete {$domain}.\n");
if ($address !== false) {
fwrite($pipes[0], "update add {$domain}. {$ttl} IN A {$address}\n");
}
fwrite($pipes[0], "\n");
fclose($pipes[0]);
$result = true;
if (fgetc($pipes[1]) !== false) {
$result = false;
}
fclose($pipes[1]);
if (fgetc($pipes[2]) !== false) {
$result = false;
}
fclose($pipes[2]);
proc_close($process);
return $result;
}
return false;
}
示例5: read_file
/**
* YunoHost - Self-hosting for all
* Copyright (C) 2012 Kload <kload@kload.fr>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
function read_file($file, $lines = 20)
{
if (!($handle = fopen($file, "r"))) {
return false;
}
$linecounter = $lines;
$pos = -2;
$beginning = false;
$text = array();
while ($linecounter > 0) {
$t = " ";
while ($t != "\n") {
if (fseek($handle, $pos, SEEK_END) == -1) {
$beginning = true;
break;
}
$t = fgetc($handle);
$pos--;
}
$linecounter--;
if ($beginning) {
rewind($handle);
}
$text[$lines - $linecounter - 1] = fgets($handle);
if ($beginning) {
break;
}
}
fclose($handle);
return array_reverse($text);
}
示例6: conversion_progress
function conversion_progress($filepath)
{
$line = '';
$f = fopen($filepath, 'r');
$cursor = -1;
fseek($f, $cursor, SEEK_END);
$char = fgetc($f);
/**
* Trim trailing newline chars of the file
*/
while ($char === " ") {
fseek($f, $cursor--, SEEK_END);
$char = fgetc($f);
}
/**
* Read until the start of file or first newline char
*/
while ($char !== false && $char !== " ") {
/**
* Prepend the new char
*/
$line = $char . $line;
fseek($f, $cursor--, SEEK_END);
$char = fgetc($f);
}
echo $line;
preg_match_all('!\\d+!', $line, $matches);
var_dump($matches);
}
示例7: tail
function tail($callback)
{
if ($fp = fopen($this->tailfile, "rb")) {
fseek($fp, 0, SEEK_END);
$fs = fstat($fp);
$ino = $fs['ino'];
while ($this->publish_count < $this->max_lines_before_quit || $this->max_lines_before_quit == 0) {
do {
do {
$ino = $this->rotate($ino);
if ($ino == FALSE) {
return FALSE;
}
$c = fgetc($fp);
$line .= $c;
} while ($c != "\n" && $c != "\r" && $c);
if ($c === FALSE) {
sleep(1);
}
} while ($c != "\n" && $c != "\r");
$this->publish_count++;
call_user_func($callback, $line);
$line = '';
$c = '';
}
fclose($fp);
} else {
echo "Can't open file\n";
}
}
示例8: read_file
protected function read_file($file, $lines)
{
//global $fsize;
try {
$handle = fopen($file, "r");
$linecounter = $lines;
$pos = -2;
$beginning = false;
$text = array();
while ($linecounter > 0) {
$t = " ";
while ($t != "\n") {
if (fseek($handle, $pos, SEEK_END) == -1) {
$beginning = true;
break;
}
$t = fgetc($handle);
$pos--;
}
$linecounter--;
if ($beginning) {
rewind($handle);
}
$text[$lines - $linecounter - 1] = fgets($handle);
if ($beginning) {
break;
}
}
fclose($handle);
return array_reverse($text);
} catch (Exception $e) {
return $e->getMessage();
}
}
示例9: run
public function run($handle, $rolloverChar, $returnMatches = false)
{
$buffer = '';
$count = strlen($this->testString);
$found = true;
for ($i = 0; $i < $count; $i++) {
$char = false;
if ($rolloverChar !== '') {
$char = $rolloverChar;
$rolloverChar = '';
} else {
$char = fgetc($handle);
}
if (substr($this->testString, $i, 1) !== $char) {
$found = false;
break;
}
}
if ($found) {
if ($returnMatches) {
$buffer = $this->testString;
}
}
return array('found' => $found, 'buffer' => $buffer, 'length' => $count, 'rolloverChar' => '');
}
示例10: checkSuokuPattern
/**
*
* This function has core logic to check Suduko board is valid or not.
* This function validate number of rows should be 9 and number of coloum should be 9
* @author Pankaj Kumar
*/
private function checkSuokuPattern()
{
$file = fopen($this->_fileName, "r");
$noOfRows = 0;
$noOfCols = 0;
$colArr = array();
while ($c = fgetc($file)) {
if (in_array($c, array("\n"))) {
// To check new line
$noOfRows++;
$colArr[] = $noOfCols;
// Store all numbers of columns
$noOfCols = 0;
} else {
$noOfCols++;
}
}
if ($noOfRows == 9 && count(array_unique($colArr)) == 1 && $colArr[0] == 9) {
// Possible condition to check Suduko board is valid or not
echo $this->_fileName . ': 1<br>';
} else {
echo $this->_fileName . ': 0<br>';
}
fclose($file);
}
示例11: queryData
function queryData($message = null)
{
global $serialConnection;
if (!empty($message)) {
// Set blocking mode for writing
stream_set_blocking($serialConnection, 1);
fputs($serialConnection, $message . "\n");
}
$timeout = time() + 10;
$line = '';
// Set non blocking mode for reading
stream_set_blocking($serialConnection, 0);
do {
// Try to read one character from the device
$c = fgetc($serialConnection);
// Wait for data to arrive
if ($c === false) {
continue 1;
}
$line .= $c;
} while ($c != "\n" && time() < $timeout);
$response = trim($line);
if (!empty($message) && $response == $message) {
// Original message echoed back, read again
sleep(1);
$response = queryData();
}
// Drain the read queue if there is anything left
while ($c !== false) {
$c = fgets($serialConnection);
}
return $response;
}
示例12: getFileExtensionFromStream
/**
* This function returns the extension associated with the file based on the file's content.
*
* @access public
* @return string the extension for the file
*/
public function getFileExtensionFromStream()
{
$ext = '';
$handle = fopen($this->uri, 'r');
if ($handle) {
$buffer = '';
for ($i = 0; !feof($handle) && $i < 1024; $i++) {
$buffer .= fgetc($handle);
}
$buffer = trim($buffer);
if (static::isBMP($buffer)) {
$ext = 'bmp';
} else {
if (static::isGIF($buffer)) {
$ext = 'gif';
} else {
if (static::isJPEG($buffer)) {
$ext = 'jpg';
} else {
if (static::isPNG($buffer)) {
$ext = 'png';
}
}
}
}
}
@fclose($handle);
return $ext;
}
示例13: extractGridFile
/**
* @param string $filename
* @return GridFile
* @throws MflParserException
*/
protected function extractGridFile($filename)
{
$file = new GridFile($filename);
$source = $file->getFileHandler();
$reader = self::getReaderForFile($file);
if (null === $reader) {
}
$x = 1;
$y = 1;
try {
while (($character = fgetc($source)) !== false) {
if ($character === "\n") {
$x++;
$y = 1;
} else {
$y++;
}
$reader->readGridFileCharacter($file, $character);
}
} catch (Exception $e) {
//echo $e->getTraceAsString();
throw new MflParserException($x, $y, $e->getMessage());
} finally {
fclose($source);
}
if ($reader->handleDefinitionForce() && sizeof($file->getDefinitions()) !== sizeof($file->getLevels())) {
throw new MflParserException($x, $y, sprintf("Number of definitions (%d) and levels (%d) doesn't match", sizeof($file->getDefinitions()), sizeof($file->getLevels())));
}
return $file;
}
示例14: walktrough
function walktrough($startdir)
{
global $filesCount, $dirsCount, $linesCount, $signsCount, $allowedext;
$startdir = preg_replace("!/\$!", '', $startdir);
$startdir .= '/';
$dir = opendir($startdir);
while ($file = readdir($dir)) {
if ($file == '.' || $file == '..') {
continue;
}
if (is_file($startdir . $file)) {
$filesCount++;
$ext = preg_replace("!.*\\.!", '', $file);
if (in_array($ext, $allowedext)) {
$file = fopen($startdir . $file, 'r');
while (fgets($file, 1000000)) {
$linesCount++;
}
rewind($file);
while (fgetc($file)) {
$signsCount++;
}
fclose($file);
}
} else {
$dirsCount++;
walktrough($startdir . $file);
}
}
closedir($dir);
}
示例15: rewind
public function rewind()
{
$this->close();
$this->f = fopen($this->filename, 'r');
$this->index = 0;
$this->current = fgetc($this->f);
}