close
編輯測試程式
# 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、MySQL與JavaScript學習手冊(第五版)
Learning PHP, MySQL & JavaScript, 5th Edition
作者: Robin Nixon
譯者: 賴屹民
出版社:歐萊禮
文章標籤
全站熱搜
留言列表