does echo equal fputs( STDout )?

喜你入骨 提交于 2019-11-29 22:18:33

According to PHP's manual page on wrappers, the answer is No.

php://output

php://output is a write-only stream that allows you to write to the output buffer mechanism in the same way as print() and echo().

print and echo write to php://output stream, whereas fputs(STDOUT) writes to php://stdout.

I did a little test:

<?php

$output = fopen('php://output', 'w');
ob_start();

echo "regular echo\n";
fwrite(STDOUT, "writing to stdout directly\n");
fwrite($output, "writing to php://output directly\n");

$ob_contents = ob_get_clean();
print "ob_contents: $ob_contents\n";

This script outputs (tested on PHP 5.2.13, windows):

writing to stdout directly
ob_contents: regular echo
writing to php://output directly

i.e. writing to STDOUT directly bypasses ob handlers.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!