LoginSignup
1
3

More than 3 years have passed since last update.

PHPの標準入力を処理する

Posted at

はじめに

こんにちは。
最近はpaizaのスキルチェック問題にはまっています。

今回はスキルチェックで使用する標準入出力用のクラスを作成したので、
まとめとして共有します!

paiza.php

class Input
{
    private $input;

    //一行
    public function one_input()
    {
        $in = trim(fgets(STDIN));
        $input = explode(" ",str_replace(array("\r\n","\r","\n"), '', $in));
        return $input;
    }

    //複数行
    public function multi_input()
    {
        while($in = trim(fgets(STDIN))){
            $input[] = explode(" ",str_replace(array("\r\n","\r","\n"),'', $in));
        }
        return $input;
    }

    //出力
    public function output($output)
    {
        echo $output . PHP_EOL;
    }
}


1
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
3