在 PHP 中,可以使用 php://output
来获取输出流(php 输出流)。
以下是一个示例代码:
<?php
// 设置响应头
header('Content-Type: text/plain');
header('Content-Disposition: attachment; filename="output.txt"');
// 获取输出流
$output = fopen('php://output', 'w');
// 写入数据到输出流
fwrite($output, 'Hello, World!');
// 关闭输出流
fclose($output);
?>
在上面的示例中,首先设置了响应头,将输出的内容作为一个附件下载。然后使用 fopen()
函数打开输出流,并使用 'w'
模式来写入数据。接下来使用 fwrite()
函数将数据写入输出流。最后使用 fclose()
函数关闭输出流。
注意:在使用 php://output
时,需要确保在写入数据之前没有输出任何内容,否则可能会导致错误。
下一篇:php exit()函数
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站