gpt4 book ai didi

php - 如何在 php 中使用 STDOUT

转载 作者:IT王子 更新时间:2023-10-29 01:06:42 25 4
gpt4 key购买 nike

我正在运行一个从 txt 文件读取流的项目,所以在 CLI 中,我写:

cat texte.txt|php index.php

在我的 index.php 文件中,我读取了流:

$handle = fopen ("php://stdin","r");

现在我有一个 $result 包含我的处理文件的结果,我想用 STDOUT 输出它,我查看了手册,但我不知道不知道如何使用它,你能给我一个使用示例吗?

最佳答案

好吧,让我再举一个关于 STDIN 的例子。和 STDOUT用法。

在 PHP 中,您使用这两个习语:

 $input = fgets(STDIN);

fwrite(STDOUT, $output);

当您从命令行使用它们时:

 cat "input.txt"  |  php script.php   >  "output.txt"

php script.php < input.txt > output.txt

echo "input..." | php script.php | sort | tee output.txt

这就是所有这些事情的作用。管道输入或管道输出。传入的部分将出现在 STDIN 中,而您的输出应该转到 STDOUT。永远不要过河,伙计们!

关于php - 如何在 php 中使用 STDOUT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8781906/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com