• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

PHP fgetc函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中fgetc函数的典型用法代码示例。如果您正苦于以下问题:PHP fgetc函数的具体用法?PHP fgetc怎么用?PHP fgetc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了fgetc函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:arckinteractive,项目名称:tidypics_cleanup,代码行数:34,代码来源:start.php


示例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;
    }
}
开发者ID:Giordano-Bruno,项目名称:GiordanoBruno,代码行数:33,代码来源:installFuncs.php


示例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;
}
开发者ID:jonasbjurel,项目名称:OPNFV-Playground,代码行数:31,代码来源:history.php


示例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;
}
开发者ID:ragi79,项目名称:Textcube,代码行数:25,代码来源:nsupdate.php


示例5: read_file

/**
 *  YunoHost - Self-hosting for all
 *  Copyright (C) 2012  Kload <[email protected]>
 *
 *  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);
}
开发者ID:realitygaps,项目名称:vpnclient_ynh,代码行数:48,代码来源:unix_func.php


示例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);
}
开发者ID:aview,项目名称:aview-content-php,代码行数:29,代码来源:ConverssionStatus.php


示例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";
     }
 }
开发者ID:nelsonjsduarte,项目名称:sapo-broker,代码行数:30,代码来源:broker_tail.php


示例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();
     }
 }
开发者ID:giangnh264,项目名称:mobileplus,代码行数:34,代码来源:FileController.php


示例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' => '');
 }
开发者ID:b4upradeep,项目名称:Pdf,代码行数:25,代码来源:StringTest.php


示例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);
 }
开发者ID:psingha3,项目名称:hartleyAssignment,代码行数:31,代码来源:checkSudoku.php


示例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;
}
开发者ID:jmcquillan,项目名称:pin-tweet-php,代码行数:33,代码来源:pintweet.php


示例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;
 }
开发者ID:bluesnowman,项目名称:Chimera,代码行数:35,代码来源:ImageBuffer.php


示例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;
 }
开发者ID:pierrelemee,项目名称:mfl-parser,代码行数:35,代码来源:MflParser.php


示例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);
}
开发者ID:jnugh,项目名称:Paradise-Bird-Project,代码行数:31,代码来源:counter.php


示例15: rewind

 public function rewind()
 {
     $this->close();
     $this->f = fopen($this->filename, 'r');
     $this->index = 0;
     $this->current = fgetc($this->f);
 }
开发者ID:vtk13,项目名称:word-counter,代码行数:7,代码来源:CharReader.php


示例16: readNextRecord

 /**
  * Returns the next record in raw format.
  *
  * @return string Next record in raw format.
  */
 private function readNextRecord()
 {
     if ($this->isEOF) {
         $this->isValidPosition = false;
     }
     $isInRecord = false;
     $recording = '';
     $lastChar = null;
     while (false !== ($char = fgetc($this->handle))) {
         $isNewArrayStart = $char === '-' && ($lastChar === "\n" || $lastChar === null);
         $lastChar = $char;
         if ($isInRecord && $isNewArrayStart) {
             fseek($this->handle, -1, SEEK_CUR);
             break;
         }
         if (!$isInRecord && $isNewArrayStart) {
             $isInRecord = true;
         }
         if ($isInRecord) {
             $recording .= $char;
         }
     }
     if ($char == false) {
         $this->isEOF = true;
     }
     return $recording;
 }
开发者ID:migros,项目名称:php-vcr,代码行数:32,代码来源:Yaml.php


示例17: encrypt

function encrypt($key, $datFile, $encFile)
{
    if (openssl_pkcs7_encrypt($datFile, $encFile, $key, array())) {
        echo "<b>Successfully encrypted: </b>";
        $tempStr = file_get_contents($encFile);
        $strOri = "MIME-Version: 1.0\nContent-Disposition: attachment; filename=\"smime.p7m\"\nContent-Type: application/x-pkcs7-mime; smime-type=enveloped-data; name=\"smime.p7m\"\nContent-Transfer-Encoding: base64\n\n";
        $fp = fopen($encFile, "w");
        fwrite($fp, str_replace($strOri, "", $tempStr));
        fclose($fp);
        echo str_replace($strOri, "", $encFile) . "<br/><br/>";
        echo "<b>Encrypted string again, with \"\\n\" replaced with &lt;br&gt and \"\\r\" replaced with [CR]:</b><br>";
        $fp = fopen($encFile, 'r');
        while (false !== ($char = fgetc($fp))) {
            if ($char == "\n") {
                echo "<br>";
            } else {
                if ($char == "\r") {
                    echo "[CR]";
                }
            }
            echo $char;
        }
    } else {
        echo "Cannot Encrypt <br/>";
    }
}
开发者ID:lethanhtung79,项目名称:dooneeweb,代码行数:26,代码来源:SinaptIQPKCS7+(Chananatch+Ruxkukbutra's+conflicted+copy+2013-07-27).php


示例18: _read

 protected function _read()
 {
     switch (fgetc($this->socket)) {
         case '+':
             return trim(fgets($this->socket), "\r\n");
         case ':':
             return (int) trim(fgets($this->socket), "\r\n");
         case '$':
             $length = (int) trim(fgets($this->socket), "\r\n");
             if ($length === -1) {
                 return null;
             }
             $return = "";
             while (strlen($return) < $length) {
                 $return .= fread($this->socket, $length - strlen($return));
             }
             fgets($this->socket);
             return $return;
         case '*':
             $length = (int) trim(fgets($this->socket), "\r\n");
             $return = [];
             for ($i = 0; $i < $length; $i++) {
                 $return[] = $this->_read();
             }
             return $return;
         case '-':
             throw new CacheException(trim(fgets($this->socket), "\r\n"));
     }
 }
开发者ID:vakata,项目名称:cache,代码行数:29,代码来源:Redis.php


示例19: tail_file

function tail_file($file, $lines)
{
    $handle = fopen($file, "r");
    if (!is_resource($handle)) {
        return '';
    }
    $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 $text;
}
开发者ID:ahastudio,项目名称:moniwiki,代码行数:32,代码来源:referer.php


示例20: TellStatus

 public static function TellStatus($GID)
 {
     if (file_exists('/tmp/' . $GID . '.curl')) {
         $Line = null;
         $TFHandle = fopen('/tmp/' . $GID . '.curl', 'r');
         $Cursor = -1;
         fseek($TFHandle, $Cursor, SEEK_END);
         $Char = fgetc($TFHandle);
         while ($Char === "\n" || $Char === "\r") {
             fseek($TFHandle, $Cursor--, SEEK_END);
             $Char = fgetc($TFHandle);
         }
         while ($Char !== false && $Char !== "\n" && $Char !== "\r") {
             $Line = $Char . $Line;
             fseek($TFHandle, $Cursor--, SEEK_END);
             $Char = fgetc($TFHandle);
         }
         $StatusArray = array('status' => 'waiting', 'completedLength' => 0, 'totalLength' => 0, 'downloadSpeed' => 0, 'PID' => 0, 'GID' => $GID);
         if (!is_null($Line)) {
             $Status = explode(';', $Line);
             if (count($Status) == 5) {
                 $StatusArray['status'] = $Status[0];
                 $StatusArray['completedLength'] = $Status[1];
                 $StatusArray['totalLength'] = $Status[2];
                 $StatusArray['downloadSpeed'] = $Status[3];
                 $StatusArray['PID'] = $Status[4];
             }
         }
         return array('result' => $StatusArray);
     } else {
         return array('error' => true);
     }
 }
开发者ID:venjek,项目名称:ocdownloader,代码行数:33,代码来源:curl.php



注:本文中的fgetc函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP fgetcsv函数代码示例发布时间:2022-05-15
下一篇:
PHP fgc函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap