編輯測試程式
# vi stdin.php
#!/usr/local/bin/php

<?php
$stdin = file ('php://stdin');
print_r ($stdin);

給予執行權限
# chmod u+x stdin.php

準備一個測試文字檔
# vi hello.txt
Hello
HelloWorld
helloworld
Hello World

測試,把文字檔cat 出來,丟給 php 程式處理
# cat hello.txt | ./stdin.php

Array
(
    [0] => Hello

    [1] => HelloWorld

    [2] => helloworld

    [3] => Hello World

)

參考資料
https://www.php.net/manual/en/features.commandline.io-streams.php

文章標籤
php stdin
全站熱搜
創作者介紹
創作者 helloworld 的頭像
helloworld

Hello World

helloworld 發表在 痞客邦 留言(0) 人氣()