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

PHP fscanf函数代码示例

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

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



在下文中一共展示了fscanf函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: read_log

function read_log()
{
    global $path;
    // Declare Array for holding data read from log file
    $name = array();
    // array for file name
    $count = array();
    // array for file count
    $file = @file("{$path}/Includes/log");
    if (empty($file)) {
        return null;
    }
    // Read the entire contents of the log file into the arrays
    $file = fopen("{$path}/Includes/log", "r");
    while ($data = fscanf($file, "%[ -~]\t%d\n")) {
        list($temp1, $temp2) = $data;
        array_push($name, $temp1);
        array_push($count, $temp2);
    }
    fclose($file);
    // $file_list contains data read from the log file as an array (filename => count)
    $file_list = @array_combine($name, $count);
    ksort($file_list);
    // Sorting it in alphabetical order of key
    return $file_list;
}
开发者ID:jcdoll,项目名称:PiezoD,代码行数:26,代码来源:functions.php


示例2: matchOrangeKey

function matchOrangeKey($cskey)
{
    $pf = fopen("conf/orangekey.conf", "r");
    list($key) = fscanf($pf, "%s");
    fclose($pf);
    return $key == $cskey;
}
开发者ID:wan-qy,项目名称:ojseven,代码行数:7,代码来源:orange.php


示例3: read_value

function read_value(&$value, $format, $allowed_values = NULL, $empty_ok = false)
{
    $handle = fopen("php://stdin", "r");
    if (!$handle) {
        return false;
    }
    while (true) {
        if ($format == "%l") {
            $value = fgets($handle);
            if ($value) {
                $value = trim($value);
            }
            $ret = strlen($value);
        } else {
            $ret = fscanf($handle, $format, $value);
        }
        if (!$empty_ok && $ret <= 0 || $allowed_values && !in_array($value, $allowed_values)) {
            echo RED . "Invalid answer '{$value}'.";
            if ($allowed_values) {
                echo "Choose from the list above: " . NOCOLOR;
            } else {
                echo "Type again: " . NOCOLOR;
            }
            continue;
        }
        break;
    }
    fclose($handle);
    return $value;
}
开发者ID:di-stars,项目名称:pinba_engine,代码行数:30,代码来源:table_generator.php


示例4: solve

function solve()
{
    fscanf(STDIN, '%d%d', $b, $n);
    $ms = array_map('intval', explode(' ', fgets(STDIN)));
    $x = 0;
    $y = 100000000000001;
    while ($x < $y) {
        $z = (int) (($x + $y) / 2);
        if (simulate($ms, $z) < $n) {
            $x = $z + 1;
        } else {
            $y = $z;
        }
    }
    $n_ = $x ? simulate($ms, $x - 1) : 0;
    foreach ($ms as $i => $m) {
        if ($x % $m == 0) {
            $n_ += 1;
            if ($n_ == $n) {
                return $i + 1;
            }
        }
    }
    return -1;
}
开发者ID:vrnss,项目名称:competitions,代码行数:25,代码来源:haircut.php


示例5: ReadDescriptionFile

 function ReadDescriptionFile($configType)
 {
     require $_SERVER['DOCUMENT_ROOT'] . "/" . $_SESSION['SiteFolder'] . "Config/Main.php";
     $Description = array();
     $handle = @fopen($_SERVER['DOCUMENT_ROOT'] . "/" . $_SESSION['SiteFolder'] . "Manager/Language/{$MainLanguage}/Configs.txt", "r");
     while (!feof($handle)) {
         $FileLine = fscanf($handle, '%s "%[^"]" "%[^"]" "%[^"]"');
         if (isset($FileLine[0]) && !empty($FileLine[0]) && strpos($FileLine[0], "//") === false) {
             if (strpos($FileLine[0], $configType) === 0) {
                 if (strpos($FileLine[0], "--") !== false) {
                     $id = rand(0, 9999);
                     $Description[$id]['ShowName'] = "HR";
                     $Description[$id]['Default'] = "";
                     $Description[$id]['Description'] = "";
                 } else {
                     $Description[$FileLine[0]]['ShowName'] = $FileLine[1];
                     $Description[$FileLine[0]]['Default'] = $FileLine[2];
                     $Description[$FileLine[0]]['Description'] = $FileLine[3];
                 }
             }
         }
     }
     fclose($handle);
     return $Description;
 }
开发者ID:BieeeLC,项目名称:OpenWeb,代码行数:25,代码来源:Config.class.php


示例6: getBanco

 public static function getBanco()
 {
     if (!isset($_SESSION['senhaBanco'])) {
         $arquivo = fopen("pass.txt", "r");
         $aux = fscanf($arquivo, "%s\t%s");
         $_SESSION['chave'] = $aux[1];
         $texto = Atalhos::decode($aux[0]);
         $tm = strlen($texto);
         //conta a quantidade de caracteres do texto
         $x = 0;
         $buf = "";
         for ($i = 1; $i <= $tm; $i++) {
             $letra[$i] = substr($texto, $x, 1);
             //isola cada caractere da string
             $cod[$i] = ord($letra[$i]);
             //converte cada caractere em seu respectivo codigo ascii
             $bin[$i] = decbin($cod[$i]);
             //converte cada codigo ascii em seu respectivo codigo binario
             if ($bin[$i] == 0) {
                 break;
             }
             $buf = $buf . $letra[$i];
             $x++;
         }
         $_SESSION['senhaBanco'] = $buf;
     }
     $db = new mysqli('localhost', 'root', $_SESSION['senhaBanco'], 'lcad');
     $db->set_charset("utf8");
     return $db;
 }
开发者ID:arturxz,项目名称:submitter,代码行数:30,代码来源:atalhos.php


示例7: input

 public static function input($message = "", $type = "", $length = '255')
 {
     gio::output("{$message}: ");
     if (empty($type)) {
         $stdin = fopen("php://stdin", "r");
         $ret = fgets($stdin, $length);
     } else {
         // Use with caution {Think buffer overflow}
         switch ($type) {
             case "integer":
                 fscanf(STDIN, "%d\n", $ret);
                 break;
             case "float":
                 fscanf(STDIN, "%f\n", $ret);
                 break;
             case "string":
                 fscanf(STDIN, "%s\n", $ret);
                 break;
             default:
                 gio::log("Invalid input type '{$type}'", E_USER_WARNING);
                 $ret = false;
                 break;
         }
     }
     return trim($ret);
 }
开发者ID:perfectcode1,项目名称:Gcoin,代码行数:26,代码来源:gio.php


示例8: getcid

function getcid()
{
    $pf = fopen("conf/cont.conf", "r");
    list($cid) = fscanf($pf, "%s");
    fclose(pf);
    return $cid;
}
开发者ID:wan-qy,项目名称:ojseven,代码行数:7,代码来源:adminfl.php


示例9: connect

 function connect()
 {
     set_time_limit(0);
     fscanf(STDIN, "%d\n", $close);
     //listens for the exit command as a boolean but represented as an integer "1"
     while ($close != 1) {
         // create low level socket
         if (!($socket = socket_create(AF_INET, SOCK_STREAM, 0))) {
             trigger_error('Error creating new socket.', E_USER_ERROR);
         }
         // bind socket to TCP port
         if (!socket_bind($socket, $this->host, $this->port)) {
             trigger_error('Error binding socket to TCP port.', E_USER_ERROR);
         }
         // begin listening connections
         if (!socket_listen($socket)) {
             trigger_error('Error listening socket connections.', E_USER_ERROR);
         }
         // create communication socket
         if (!($comSocket = socket_accept($socket))) {
             trigger_error('Error creating communication socket.', E_USER_ERROR);
         }
         // read socket input
         $socketInput = socket_read($comSocket, 1024);
         // convert to uppercase socket input
         $socketOutput = strtoupper(trim($socketInput)) . "n";
         // write data back to socket server
         if (!socket_write($comSocket, $socketOutput, strlen($socketOutput))) {
             trigger_error('Error writing socket output', E_USER_ERROR);
         }
     }
     close($socket, $comSocket);
 }
开发者ID:anubhaBhargava,项目名称:OpenRecommender,代码行数:33,代码来源:TCP.class.php


示例10: gettl

function gettl()
{
    $pf = fopen("conf/time.conf", "r");
    list($hh, $mm) = fscanf($pf, "%d:%d");
    fclose($pf);
    $tl = $hh * 10000 + $mm * 100;
    return $tl;
}
开发者ID:wan-qy,项目名称:ojseven,代码行数:8,代码来源:cur.php


示例11: gets

function gets(&$s)
{
    $ta = array();
    $s = "";
    $ta = fscanf(STDIN, "%s\n");
    $s = $ta[0];
    return $ta[0];
}
开发者ID:evelynmitchell,项目名称:pdq,代码行数:8,代码来源:mva.php


示例12: run_the_numbers

function run_the_numbers($argv, $step = 5, $start = 1, $end = 40)
{
    define('DEFAULT_DBONUS', 5);
    // *** default dueling bonus expressed as % ***
    define('DEFAULT_LALPHA', 25);
    // *** default Importance of Level Difference expressed as 1/a ***
    define('STARTING_STR', 10);
    // *** Level 1 STR ***
    define('STR_PER_LVL', 5);
    // *** STR Added per level ***
    define('STARTING_HP', 150);
    // *** Level 1 HP ***
    define('HP_PER_LVL', 25);
    // *** HP Added per level ***
    $funcs = array("1", "2");
    // *** suffixes of calculate_experience functions ***
    $defaultFunc = end($funcs);
    // *** last function listed is default because it is most likely the newest ***
    if (isset($argv) && $argv[1] == '-d') {
        // *** Run this script with -d to use all default values
        $funcChoice = $defaultFunc;
        $dbonus = DEFAULT_DBONUS;
        $alpha = DEFAULT_LALPHA;
    } else {
        // *** Otherwise, important values are determined interactively ***
        echo "Run this script with -d to automatically use all default values\n";
        $funcChoice = null;
        echo "Please choose an exp function (", implode(',', $funcs), ") [", $defaultFunc, "]: ";
        fscanf(STDIN, "%d\n", $funcChoice);
        if (!in_array($funcChoice, $funcs)) {
            $funcChoice = $defaultFunc;
        }
        echo "Please specify a importance of level difference 1/[", DEFAULT_LALPHA, "] : ";
        fscanf(STDIN, "%d\n", $alpha);
        if (!is_numeric($alpha)) {
            $alpha = DEFAULT_LALPHA;
        }
        echo "Please specify dueling bonus [", DEFAULT_DBONUS, "]% :";
        fscanf(STDIN, "%d\n", $dbonus);
        if (!is_numeric($dbonus)) {
            $dbonus = DEFAULT_DBONUS;
        }
    }
    define('DUELING_BONUS', $dbonus);
    define('LEVEL_MOD_ALPHA', $alpha <= 0 ? 1 : $alpha);
    $func = "calculate_experience" . $funcChoice;
    for ($attacker = $start; $attacker <= $end; $attacker = $attacker + $step) {
        for ($victim = $start; $victim <= $end; $victim = $victim + $step) {
            $rounds = calculate_average_duel_length($attacker, $victim);
            echo "Level {$attacker} (", max_calculate_health($attacker), "HP, ", calculate_average_dmg($victim), "DMG-IN, ", calculate_average_dmg($attacker), "DMG-OUT) attacks Level {$victim} (", max_calculate_health($victim), "HP)\n";
            echo "**** DUEL (" . $rounds . " rounds): " . calculate_duel($func, $attacker, $victim) . "\n";
            echo "**** SINGLE * ROUNDS: " . calculate_single_attack($func, $attacker, $victim) * $rounds . "\n";
            echo "**** SINGLE: " . calculate_single_attack($func, $attacker, $victim) . "\n";
            //echo "**** SINGLE w/ KILL: ".(calculate_single_attack($func, $attacker, $victim, true)*10)."\n";
            echo "--------------------------------------------\n";
        }
    }
}
开发者ID:reillo,项目名称:ninjawars,代码行数:58,代码来源:experience_tests.php


示例13: fscanfe

function fscanfe($handle, $format, Closure $callback)
{
    $filename = stream_get_meta_data($handle)['uri'];
    $filesize = filesize($filename);
    do {
        $lineinfo = fscanf($handle, $format);
        call_user_func_array($callback, array($lineinfo));
    } while (ftell($handle) != $filesize);
}
开发者ID:T-SummerStudent,项目名称:new,代码行数:9,代码来源:helpers.php


示例14: readINT

 /**
  * @return int the users console input as string
  */
 protected function readINT()
 {
     // initialize integer that should be returned
     $number = null;
     // read number from input stream
     fscanf($this->inputHandle, "%d\n", $number);
     // return the parsed number
     return $number;
 }
开发者ID:SMenigat,项目名称:nwt-php,代码行数:12,代码来源:PHPConsoleApp.php


示例15: compute

function compute()
{
    fscanf(STDIN, "%d %d\n", $w, $b);
    if ($b % 2 == 1) {
        return "BLACK";
    } else {
        return "WHITE";
    }
}
开发者ID:jefferyyuan,项目名称:Google-Code-Jam,代码行数:9,代码来源:A.php


示例16: read_fline

function read_fline($fln)
{
    if (!is_file($fln)) {
        return "";
    }
    $ipf = fopen($fln, "r");
    list($ret) = fscanf($ipf, "%s");
    fclose($ipf);
    return $ret;
}
开发者ID:wan-qy,项目名称:ojseven,代码行数:10,代码来源:admin.php


示例17: getInput

function getInput($mask)
{
    global $nimode;
    if ($nimode) {
        print "[non-interactive mode]\n";
        return true;
    }
    fscanf(STDIN, "{$mask}\n", $x);
    return $x;
}
开发者ID:rrsc,项目名称:freemed,代码行数:10,代码来源:install.php


示例18: read

 static function read($format = null)
 {
     do {
         if ($format) {
             fscanf(self::get_stdin(), $format . "\n", $in);
         } else {
             $in = fgets(self::get_stdin());
         }
     } while ($in === false);
     return $in;
 }
开发者ID:boolive,项目名称:core,代码行数:11,代码来源:CLI.php


示例19: compute

function compute()
{
    fscanf(STDIN, "%d %d %d\n", $n, $m, $a);
    if ($a > $n * $m) {
        return "IMPOSSIBLE";
    } else {
        $x = ($a - 1) % $n + 1;
        $y = floor(($a - 1) / $n) + 1;
        return "0 1 {$n} 0 {$x} {$y}";
    }
}
开发者ID:jefferyyuan,项目名称:Google-Code-Jam,代码行数:11,代码来源:B.php


示例20: parseMemInfo

 /**
  * Parses the meminfo.
  * 
  * @return void
  */
 private function parseMemInfo()
 {
     $memInfo = array();
     $fh = fopen($this->filename, 'r');
     while (!feof($fh)) {
         if (fscanf($fh, '%[^:]%*[: ]%u%*[^0-9]', $key, $value)) {
             $memInfo[strtolower($key)] = $value;
         }
     }
     $this->memInfo = $memInfo;
 }
开发者ID:jou,项目名称:ymc-components,代码行数:16,代码来源:meminfo.php



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
PHP fseek函数代码示例发布时间:2022-05-15
下一篇:
PHP fs_require_template函数代码示例发布时间: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