Ed *_*eal 12 php stdout echo stderr
STDOUT在PHP中编写大块时,可以这样做:
echo <<<END_OF_STUFF
lots and lots of text
over multiple lines
etc.etc
END_OF_STUFF;
Run Code Online (Sandbox Code Playgroud)
(即heredoc)
我需要做类似的事情,但是STDERR.是否有另一个命令,echo但使用STDERR相反?
Mch*_*chl 20
是的,使用php:// stream wrapper:http://php.net/manual/en/wrappers.php.php
$stuff = <<<END_OF_STUFF
lots and lots of text
over multiple lines
etc.etc
END_OF_STUFF;
$fh = fopen('php://stderr','a'); //both (a)ppending, and (w)riting will work
fwrite($fh,$stuff);
fclose($fh);
Run Code Online (Sandbox Code Playgroud)
Lix*_*Lix 18
对于简单的解决方案 - 试试这个
file_put_contents('php://stderr', 'This text goes to STDERR',FILE_APPEND);
Run Code Online (Sandbox Code Playgroud)
该FILE_APPEND参数将追加数据而不会覆盖它.您还可以使用fopen和fwrite函数直接写入错误流.
更多信息可以在http://php.net/manual/en/features.commandline.io-streams.php找到
| 归档时间: |
|
| 查看次数: |
10388 次 |
| 最近记录: |