如何防止system()函数在浏览器中打印输出?

Ste*_*eve 1 php shell command-line curl system

我正在使用system()PHP函数来运行这样的curl命令,system("curl command here",$output);但它会在屏幕上显示结果.有什么方法可以避免这种输出?

hak*_*kre 5

你正在使用错误的功能.根据文件:

system()就像函数的C版本一样,它执行给定的命令并输出结果.

所以它总是输出.使用execDocs而不是返回(而不是输出)程序输出:

$last =  exec("curl command here", $output, $status);
$output = implode("\n", $output);
Run Code Online (Sandbox Code Playgroud)

或(只是为了完整性)使用输出缓冲文件:

ob_start();
system("curl command here", $status);
$output = ob_get_clean();
Run Code Online (Sandbox Code Playgroud)