当前位置: 首页>>代码示例>>PHP>>正文


PHP readline函数代码示例

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


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

示例1: readMove

 private function readMove()
 {
     do {
         $isValid = true;
         $move = readline("Your move: ");
         $move = explode(",", $move);
         if (count($move) != 2) {
             $isValid = false;
         }
         foreach ($move as $k => $m) {
             $m = trim($m);
             $move[$k] = $m;
             if ($m !== '0' && $m !== '1' && $m !== '2') {
                 $isValid = false;
             }
         }
         if ($isValid && $this->deck[$move[0]][$move[1]] != 0) {
             $isValid = false;
         }
         if (!$isValid) {
             echo "Your move is wrong format, value or position (format: ROW,COLUMN). <Example> 0,0 or 0,1 or 1,2\n";
         }
     } while (!$isValid);
     return $move;
 }
开发者ID:vnjp22,项目名称:TicTacToe,代码行数:25,代码来源:TicTacToe.php

示例2: authCode

 public function authCode()
 {
     while (!is_null($this->_last_fetch_captcha) and microtime(true) - $this->_last_fetch_captcha < 2) {
         usleep(1000);
     }
     $this->_last_fetch_captcha = microtime(true);
     // 1. 先輸入認證碼
     $url = 'http://lvr.land.moi.gov.tw/N11/ImageNumberN13';
     $response = http_get($url);
     $message = http_parse_message($response);
     if (!preg_match('#JSESSIONID=([^;]*);#', $message->headers['Set-Cookie'], $matches)) {
         throw new Exception("找不到 JSESSIONID");
     }
     $this->cookie = $matches[1];
     $tmpfp = tmpfile();
     fwrite($tmpfp, $message->body);
     $tmp_meta = stream_get_meta_data($tmpfp);
     $return_var = 0;
     system('jp2a ' . escapeshellarg($tmp_meta['uri']), $return_var);
     if ($return_var == 1) {
         // 不是圖片,就再試一次...
         return $this->authCode();
     }
     fclose($tmpfp);
     $code = readline("請輸入認證碼: ");
     // 2. 輸入認證碼
     $response = http_post_fields('http://lvr.land.moi.gov.tw/N11/login.action', array('command' => 'login', 'count' => 0, 'rand_code' => intval($code), 'in_type' => 'land'), array(), array('cookies' => array('JSESSIONID' => $this->cookie)));
     if (strpos(http_parse_message($response)->body, '驗證碼錯誤')) {
         error_log('驗證碼錯誤,重試一次');
         $this->authCode();
     }
 }
开发者ID:royc,项目名称:realprice,代码行数:32,代码来源:crawler.php

示例3: go

function go($board, $colour, $cpu)
{
    $col = 0;
    showBoard($board);
    $cols = cols($board);
    if ($cpu == 0) {
        while (!in_array($col, $cols)) {
            $msg = 'player ' . $colour . ' - please choose a column (' . implode(',', $cols) . '): ';
            $col = readline($msg);
        }
    } else {
        sleep(0.5);
        print 'cpu thinking... ' . "\n";
        $col = $cols[array_rand($cols, 1)];
    }
    sleep(1);
    array_push($board[$col], $colour);
    if (check($board, $col)) {
        win($board, $colour);
        sleep(1);
        return 1;
    } else {
        return $board;
    }
}
开发者ID:skiv71,项目名称:connect4,代码行数:25,代码来源:game.php

示例4: input

 public static function input($prefix = '')
 {
     if (static::readline_support()) {
         return readline($prefix);
     }
     return fgets(STDIN);
 }
开发者ID:anchorcms,项目名称:anchor-cms,代码行数:7,代码来源:cli.php

示例5: _getAction

 protected static function _getAction()
 {
     do {
         $action = readline("action > ");
         if ($action === false) {
             break;
         }
         $action = trim($action);
         if ($action === '') {
             echo implode("\n", Action::$whitelist), "\n\n";
         } else {
             if (in_array($action, ['q', 'quit'])) {
                 return false;
             } else {
                 if ($action) {
                     if (!Action::isWhitelisted($action)) {
                         echo "Action not found\n";
                         $action = '';
                     }
                 }
             }
         }
     } while ($action === '');
     return $action;
 }
开发者ID:ligro,项目名称:php-utils,代码行数:25,代码来源:cli.php

示例6: main

 protected function main()
 {
     if (!file_exists($this->configPath)) {
         mkdir($this->configPath, 0777, true);
     }
     $this->readConfig();
     if (!$this->config['email']) {
         throw new \Exception('Email is required for initialization.');
     }
     if (!$this->config['client-id'] || !$this->config['client-secret']) {
         throw new \Exception('Amazon Cloud Drive API credentials are required for initialization.');
     }
     $this->saveConfig();
     $this->cacheStore = $this->generateCacheStore();
     $this->clouddrive = new CloudDrive($this->config['email'], $this->config['client-id'], $this->config['client-secret'], $this->cacheStore);
     $response = $this->clouddrive->getAccount()->authorize();
     if (!$response['success']) {
         $this->output->writeln($response['data']['message']);
         if (isset($response['data']['auth_url'])) {
             $this->output->writeln('Navigate to the following URL and paste in the redirect URL here.');
             $this->output->writeln($response['data']['auth_url']);
             $redirectUrl = readline();
             $response = $this->clouddrive->getAccount()->authorize($redirectUrl);
             if ($response['success']) {
                 $this->output->writeln('<info>Successfully authenticated with Amazon Cloud Drive.</info>');
                 return;
             }
             $this->output->getErrorOutput()->writeln('<error>Failed to authenticate with Amazon Cloud Drive: ' . json_encode($response['data']) . '</error>');
         }
     } else {
         $this->output->writeln('<error>That user is already authenticated with Amazon Cloud Drive.</error>');
     }
 }
开发者ID:Zn4rK,项目名称:clouddrive-php,代码行数:33,代码来源:InitCommand.php

示例7: mal_readline

function mal_readline($prompt)
{
    global $HISTORY_FILE;
    static $history_loaded = false;
    // Load the history file
    if (!$history_loaded) {
        $history_loaded = true;
        if (is_readable($HISTORY_FILE)) {
            if ($file = fopen($HISTORY_FILE, "r")) {
                while (!feof($file)) {
                    $line = fgets($file);
                    if ($line) {
                        readline_add_history($line);
                    }
                }
                fclose($file);
            }
        }
    }
    $line = readline($prompt);
    if ($line === false) {
        return NULL;
    }
    readline_add_history($line);
    // Append to the history file
    if (is_writable($HISTORY_FILE)) {
        if ($file = fopen($HISTORY_FILE, "a")) {
            fputs($file, $line . "\n");
            fclose($file);
        }
    }
    return $line;
}
开发者ID:mdkarch,项目名称:mal,代码行数:33,代码来源:readline.php

示例8: read

	public function read($path) {
		$this->_historize(\AIP\lib\clnt\cmnctr\Communicator::i()->get_last_history());
		
		$line = readline($this->_get_input_question($path));
		
		return $line;
	}
开发者ID:rATRIJS,项目名称:AIP,代码行数:7,代码来源:Readline.php

示例9: listenForInput

 private function listenForInput()
 {
     echo "Please type a letter: ";
     $input = readline();
     $this->handleInput($input);
     $this->listenForInput();
 }
开发者ID:bertrandmoulard,项目名称:hangman_exercise,代码行数:7,代码来源:hangman.php

示例10: actionRandAlbom

 /**
  * Выбрать альбом для прослушивания
  */
 public function actionRandAlbom($unusual = 0)
 {
     if ($unusual) {
         $played = implode(',', ArrayHelper::map(Played::find()->all(), 'id', 'source_id'));
         $alboms = Source::find()->where("id NOT IN (" . $played . ")")->andWhere(['status' => 3])->all();
         if ($alboms) {
             $rand = rand(0, count($alboms));
             $new_played = new Played();
             $new_played->source_id = $alboms[$rand]->id;
             $new_played->save(false);
             echo "Ставь " . $alboms[$rand]->title . " -- " . $alboms[$rand]->author->name . PHP_EOL;
         } else {
             echo "Ничего нет" . PHP_EOL;
         }
     } else {
         $played = implode(',', ArrayHelper::map(Played::find()->all(), 'id', 'source_id'));
         $alboms = Source::find()->where("id NOT IN (" . $played . ")")->andWhere(['status' => 1])->all();
         if ($alboms) {
             $rand = rand(0, count($alboms));
             $data = readline("Устроит " . $alboms[$rand]->title . " -- " . $alboms[$rand]->author->name . " ? Y или N ? ");
             if ($data == 'N') {
                 $this->actionRandAlbom();
             } else {
                 $new_played = new Played();
                 $new_played->source_id = $alboms[$rand]->id;
                 $new_played->save(false);
                 echo "Ставь " . $alboms[$rand]->title . " -- " . $alboms[$rand]->author->name . PHP_EOL;
             }
         } else {
             echo "Ничего нет" . PHP_EOL;
         }
     }
 }
开发者ID:roman1970,项目名称:lis,代码行数:36,代码来源:RandController.php

示例11: loopException

function loopException()
{
    while (true) {
        readline('Press any key to continue..');
        exceptionFunction();
    }
}
开发者ID:Staberinde,项目名称:nuclide,代码行数:7,代码来源:test-client.php

示例12: prompt

function prompt($parser, $item, $category, $locations)
{
    echo "\n" . $item->title() . "\n";
    echo $locations[0]['name'] . ' <-> ' . $locations[1]['name'] . "\n";
    if ($category) {
        echo $category['name'] . " ok?\n";
    }
    while (true) {
        $in = readline('> ');
        if ($in == 'q') {
            return;
        } elseif ($in == 'm') {
            echo $item->title() . "\n";
            echo $item->guid() . "\n";
            echo $item->description() . "\n";
            echo $item->content() . "\n";
        } elseif ($in == 'no') {
            return;
        } elseif ($in == 'h') {
            foreach ($parser->getClassifier()->getAllCategories() as $category) {
                echo "  " . $category['id'] . "> " . $category['name'] . "\n";
            }
            echo "  q> skip\n";
            echo "  m> more\n";
        } else {
            if (!$category) {
                $category = $parser->getClassifier()->getCategory($in);
            }
            if ($category) {
                return $category;
            }
        }
    }
}
开发者ID:robyoung,项目名称:war-and-peace,代码行数:34,代码来源:add-items.php

示例13: up

 public function up()
 {
     $table = $this->table('archive_publication');
     $table->addColumn('name', 'string', array('length' => 40))->addColumn('inactive', 'boolean', array('default' => 0))->addIndex('inactive')->create();
     $table = $this->table('archive_issue');
     $table->addColumn('issue', 'integer')->addColumn('date', 'date')->addColumn('publication', 'integer')->addColumn('inactive', 'boolean', array('default' => 0))->addIndex('publication')->addIndex('issue')->addIndex('inactive')->addIndex(array('issue', 'publication'), array('unique' => true))->addForeignKey('publication', 'archive_publication', 'id')->create();
     $table = $this->table('archive_file');
     $table->addColumn('issue', 'integer')->addColumn('issue_id', 'integer', array('null' => true))->addColumn('publication', 'integer')->addColumn('part', 'string', array('length' => 5))->addColumn('filename', 'string', array('length' => 255))->addColumn('content', 'text')->addIndex('part')->create();
     $this->execute("ALTER TABLE `archive_file` ADD FULLTEXT(`content`);");
     $db = readline("Please enter the name of the archive database to copy data from. Phinx must have read access to this database. To skip this step, press CTRL-D.\n");
     if (!$db) {
         return;
     }
     $this->execute("INSERT INTO archive_publication (id, name) SELECT PubNo AS id, PubName AS name FROM `" . $db . "`.Publications");
     $this->execute("INSERT INTO archive_issue (id, issue, date, publication) SELECT id AS id, IssueNo AS issue, PubDate AS date, PubNo AS publication FROM `" . $db . "`.Issues");
     $this->execute("INSERT INTO archive_file (issue, publication, part, filename, content) SELECT DISTINCT IssueNo AS issue, PubNo AS publication, Title AS part, FileName AS filename, Content AS content FROM `" . $db . "`.Files");
     // Now correct issue IDs
     foreach ($this->fetchAll('SELECT id, issue, publication FROM archive_file') as $file) {
         $issue = $this->fetchRow('SELECT id FROM archive_issue WHERE issue = ' . $file['issue'] . ' AND publication = ' . $file['publication']);
         if ($issue['id'] == NULL) {
             echo '-> Issue record could not be found for file ' . $file['id'] . ' supposed issue ' . $file['issue'] . ' in publication ' . $file['publication'] . "\n";
             $this->execute('UPDATE archive_file SET issue_id = NULL WHERE id = ' . $file['id']);
             continue;
         }
         $this->execute('UPDATE archive_file SET issue_id = ' . $issue['id'] . ' WHERE id = ' . $file['id']);
     }
     $table = $this->table('archive_file');
     $table->removeColumn('issue')->removeColumn('publication')->addForeignKey('issue_id', 'archive_issue', 'id')->addIndex('issue_id')->save();
 }
开发者ID:felixonline,项目名称:core,代码行数:29,代码来源:20150827094001_issue_archive.php

示例14: create

    public function create()
    {
        echo "You must create config file in next step \n";
        $user = readline("Username datebase: ");
        $password = readline("Password database: ");
        $host = readline("Host database: ");
        $driver = readline("Driver datebase: ");
        $dbname = readline("Datebase name: ");
        $templateClass = readline("Template class(default {$this->defaults['template_class']}):");
        $pathCRUD = readline("where to put crud files?(give absolute path): ");
        /** default settings * */
        !empty($templateClass) ?: ($templateClass = $this->defaults['template_class']);
        $output = <<<EOT
            <?php return array(
                'db' => [
                  'dsn'=> '{$driver}:host={$host};dbname={$dbname}',
                  'username' => '{$user}',
                  'password' => '{$password}',
                   ],
                 'path_crud' => '{$pathCRUD}',
                 'template_class' => '{$templateClass}'
                 );
EOT;
        if (!file_put_contents(self::CONFIG_FILE, $output)) {
            chmod(self::CONFIG_FILE, fileperms(self::CONFIG_FILE) | 128 + 16 + 2);
            throw new ScaffoldingException('failed create config file');
        }
    }
开发者ID:dawid-daweb,项目名称:scaffolding-generator,代码行数:28,代码来源:ScaffoldingConfig.php

示例15: read

 /**
  * @brief Read a line, optionally setting the completer
  *
  * @param string $prompt The prompt to display
  * @param ReadlineAutoCompleter $completer The completer instance
  * @param boolean $autohistory Add command to history automatically (default is false)
  */
 static function read($prompt = null, ReadlineAutoCompleter $completer = null, $autohistory = false)
 {
     $oldcompleter = null;
     // If we got an autocompleter, assign it
     if ($completer) {
         // Save a copy of the old completer if any
         if (self::$completer && $completer !== self::$completer) {
             $oldcompleter = self::$completer;
         }
         // Assign and set up the proxy call
         self::$completer = $completer;
         readline_completion_function(array('Readline', '_rlAutoCompleteProxy'));
     }
     // Read the line
     $ret = readline($prompt);
     // Restore old completer (if any) and add the command to the history
     // if autohistory is enabled.
     if ($oldcompleter) {
         self::$completer = $oldcompleter;
     }
     if ($autohistory) {
         self::addHistory($ret);
     }
     return $ret;
 }
开发者ID:noccy80,项目名称:lepton-ng,代码行数:32,代码来源:console.php


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